public void Parse(string xmlData)
        {
            try
            {
                if (xmlData.Trim().Length > 0)
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.LoadXml(xmlData);

                    _Errors.Clear();
                    XmlNodeList errorNodes;
                    errorNodes = xdoc.SelectNodes("/RateV4Response/Error");
                    if (errorNodes != null)
                    {
                        foreach (XmlNode en in errorNodes)
                        {
                            USPSError e = new USPSError(en);
                            _Errors.Add(e);
                        }
                    }

                    _Packages.Clear();
                    XmlNodeList packageNodes;
                    packageNodes = xdoc.SelectNodes("/RateV4Response/Package");
                    if (packageNodes != null)
                    {
                        foreach (XmlNode pn in packageNodes)
                        {
                            DomesticPackage p = new DomesticPackage(pn);
                            _Packages.Add(p);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                USPSError e = new USPSError();
                e.Source = ex.StackTrace;
                e.Description = "BV Software Parsing Error: " + ex.Message;
                _Errors.Add(e);
            }

        }
        public void Parse(string xmlData)
        {
            try
            {
                if (xmlData.Trim().Length > 0)
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.LoadXml(xmlData);

                    _Errors.Clear();
                    XmlNodeList errorNodes;
                    errorNodes = xdoc.SelectNodes("/RateV4Response/Error");
                    if (errorNodes != null)
                    {
                        foreach (XmlNode en in errorNodes)
                        {
                            USPSError e = new USPSError(en);
                            _Errors.Add(e);
                        }
                    }

                    _Packages.Clear();
                    XmlNodeList packageNodes;
                    packageNodes = xdoc.SelectNodes("/RateV4Response/Package");
                    if (packageNodes != null)
                    {
                        foreach (XmlNode pn in packageNodes)
                        {
                            DomesticPackage p = new DomesticPackage(pn);
                            _Packages.Add(p);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                USPSError e = new USPSError();
                e.Source      = ex.StackTrace;
                e.Description = "BV Software Parsing Error: " + ex.Message;
                _Errors.Add(e);
            }
        }
        private List<DomesticPackage> OptimizePackages(IShipment shipment)
        {
            List<DomesticPackage> result = new List<DomesticPackage>();

            // Determine what service to use when processing
            DomesticServiceType service = DomesticServiceType.All;
            service = this.Settings.GetServiceForProcessing();
           
            // Get max weight for this service
            decimal _maxWeight = CalculateMaxWeightPerPackage(service, this.Settings.PackageType);

            // Create many boxes if we exceed max weight
            PackageOptimizer optimizer = new PackageOptimizer(_maxWeight);                                    
            List<IShippable> weightOptimizedPackages = optimizer.OptimizePackagesToMaxWeight(shipment);

            int counter = 0;
            foreach (IShippable s in weightOptimizedPackages)
            {                
                DomesticPackage pak = new DomesticPackage();
                pak.Id = counter.ToString();
                pak.ZipDestination = MerchantTribe.Web.Text.TrimToLength(shipment.DestinationAddress.PostalCode, 5);
                pak.ZipOrigination = MerchantTribe.Web.Text.TrimToLength(shipment.SourceAddress.PostalCode, 5);
                
                pak.Container = this.Settings.PackageType;
                // If we're using first class service, make sure we have a valid package type
                if (service == DomesticServiceType.FirstClass)
                {
                    if ((int)pak.Container < 100)
                    {
                        if (pak.Ounces < 3.5m)
                        {
                            pak.Container = DomesticPackageType.FirstClassLetter;
                        }
                        else
                        {
                            pak.Container = DomesticPackageType.FirstClassParcel;
                        }
                    }
                }

                pak.Ounces = MerchantTribe.Web.Conversions.DecimalPoundsToOunces(s.BoxWeight);
                pak.Pounds = (int)Math.Floor(s.BoxWeight);
                pak.Service = service;

                counter++;
                result.Add(pak);
            }
            
            return result;
        }