private List <InternationalPackage> OptimizePackages(IShipment shipment) { var optimizedPackages = shipment.Items; var counter = 0; var result = new List <InternationalPackage>(); foreach (var s in optimizedPackages) { var pak = new InternationalPackage { Id = counter.ToString(), DestinationCountry = shipment.DestinationAddress.CountryData.SystemName, ZipOrigination = Text.TrimToLength(shipment.SourceAddress.PostalCode, 5) }; var weightInPounds = s.BoxWeight; if (s.BoxWeightType == WeightType.Kilograms) { weightInPounds = Conversions.KilogramsToPounds(s.BoxWeight); } pak.Pounds = (int)Math.Floor(weightInPounds); pak.Ounces = Conversions.DecimalPoundsToOunces(weightInPounds); if (s.BoxLengthType == LengthType.Centimeters) { pak.Width = Conversions.CentimetersToInches(s.BoxWidth); pak.Height = Conversions.CentimetersToInches(s.BoxHeight); pak.Length = Conversions.CentimetersToInches(s.BoxLength); } else { pak.Width = s.BoxWidth; pak.Height = s.BoxHeight; pak.Length = s.BoxLength; } pak.Container = InternationalContainerType.Rectangular; pak.CommercialRates = false; counter++; result.Add(pak); } return(result); }
private InternationalPackage CreateInternationalPackage(GetShippingOptionRequest shipmentPackage, List <USPSVolumetrics> item, MailType baseService) { decimal weightSum = item.Sum(i => i.Weight); int pounds = _uspsVolumetricsService.GetWeightInPounds(weightSum); int ounces = _uspsVolumetricsService.GetWeightRemainderInOunces(pounds, weightSum); var package = new InternationalPackage { OriginZip = _uspsSettings.ZipPostalCodeFrom, Country = shipmentPackage.ShippingAddress.Country.Name, Length = item.Sum(i => i.Length), Height = item.Sum(i => i.Height), Width = item.Sum(i => i.Width), Pounds = pounds, Ounces = ounces, ValueOfContents = $"{GetPackageSubTotal(shipmentPackage):0.00}", Container = "RECTANGULAR", SelectedMailType = baseService, ExtraServices = GetExtraServicesForInsurance() }; return(package); }
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); }