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);
        }
Example #2
0
        private List <InternationalPackage> OptimizePackages(IShipment shipment)
        {
            List <InternationalPackage> result = new List <InternationalPackage>();

            // Determine what service to use when processing
            string destinationCountry = shipment.DestinationAddress.CountryData.Name;

            // Get max weight for this service
            decimal _maxWeight = InternationalService.GetInternationalWeightLimit(destinationCountry);

            // 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)
            {
                InternationalPackage pak = new InternationalPackage();
                pak.Id = counter.ToString();
                pak.DestinationCountry = shipment.DestinationAddress.CountryData.Name;
                pak.ZipOrigination     = MerchantTribe.Web.Text.TrimToLength(shipment.SourceAddress.PostalCode, 5);

                pak.Container       = InternationalContainerType.Rectangular;
                pak.CommercialRates = false;

                pak.Ounces = MerchantTribe.Web.Conversions.DecimalPoundsToOunces(s.BoxWeight);
                pak.Pounds = (int)Math.Floor(s.BoxWeight);
                pak.Length = 6;
                pak.Height = 3;
                pak.Width  = 1;

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

            return(result);
        }
        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;
        }
        private List<InternationalPackage> OptimizePackages(IShipment shipment)
        {
            List<InternationalPackage> result = new List<InternationalPackage>();

            // Determine what service to use when processing            
            string destinationCountry = shipment.DestinationAddress.CountryData.Name;
            
            // Get max weight for this service
            decimal _maxWeight = InternationalService.GetInternationalWeightLimit(destinationCountry);

            // 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)
            {
                InternationalPackage pak = new InternationalPackage();
                pak.Id = counter.ToString();
                pak.DestinationCountry = shipment.DestinationAddress.CountryData.Name;
                pak.ZipOrigination = MerchantTribe.Web.Text.TrimToLength(shipment.SourceAddress.PostalCode, 5);

                pak.Container = InternationalContainerType.Rectangular;
                pak.CommercialRates = false;

                pak.Ounces = MerchantTribe.Web.Conversions.DecimalPoundsToOunces(s.BoxWeight);
                pak.Pounds = (int)Math.Floor(s.BoxWeight);
                pak.Length = 6;
                pak.Height = 3;
                pak.Width = 1;
                                
                counter++;
                result.Add(pak);
            }
            
            return result;
        }