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 DomesticPackage CreateDomesticPackage(GetShippingOptionRequest shipmentPackage, List <USPSVolumetrics> item, ServiceTypes baseService) { decimal weightSum = item.Sum(i => i.Weight); int pounds = _uspsVolumetricsService.GetWeightInPounds(weightSum); int ounces = _uspsVolumetricsService.GetWeightRemainderInOunces(pounds, weightSum); var package = new DomesticPackage { ZipOrigination = _uspsSettings.ZipPostalCodeFrom, ZipDestination = shipmentPackage.ShippingAddress.ZipPostalCode, Length = item.Sum(i => i.Length), Height = item.Sum(i => i.Height), Width = item.Sum(i => i.Width), Pounds = pounds, Ounces = ounces, Value = $"{GetPackageSubTotal(shipmentPackage):0.00}", Container = "RECTANGULAR", ShipDate = $"{DateTime.Now.Date:dd-MMM-yyyy}", SelectedServiceType = baseService, SpecialServices = GetSpecialServicesForInsurance(baseService) }; return(package); }
private List <DomesticPackage> OptimizePackages(IShipment shipment) { // Determine what service to use when processing var service = Settings.GetServiceForProcessing(); var optimizedPackages = shipment.Items; var counter = 0; var result = new List <DomesticPackage>(); foreach (var s in optimizedPackages) { var pak = new DomesticPackage { Id = counter.ToString(), ZipDestination = Text.TrimToLength(shipment.DestinationAddress.PostalCode, 5), 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); pak.Service = service; 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 = 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; } } } counter++; result.Add(pak); } return(result); }
public Package() { _package = new DomesticPackage(); }