Ejemplo n.º 1
0
        public static bool Is2into1(ItemPackageDTO package1, ItemPackageDTO package2)
        {
            if (!package1.PackageHeight.HasValue ||
                !package1.PackageLength.HasValue ||
                !package1.PackageWidth.HasValue ||
                !package2.PackageHeight.HasValue ||
                !package2.PackageLength.HasValue ||
                !package2.PackageWidth.HasValue)
            {
                return(true);
            }

            var size1 = new List <decimal>()
            {
                package1.PackageLength.Value, package1.PackageWidth.Value, package1.PackageHeight.Value
            };
            var size2 = new List <decimal>()
            {
                package2.PackageLength.Value, package2.PackageWidth.Value, package2.PackageHeight.Value
            };

            size1.Sort();
            size2.Sort();

            var isIn = true;

            for (var i = 0; i < 3; i++)
            {
                isIn = isIn && size1[i] >= size2[i];
            }

            return(isIn);
        }
Ejemplo n.º 2
0
        public static bool FitInPackage(ItemPackageDTO boxPackage, ItemPackageDTO testPackage)
        {
            //NOTE: if one of them is empty, skip validation
            if (boxPackage.IsEmpty || testPackage.IsEmpty)
            {
                return(true);
            }

            if (boxPackage.MaxVolume.HasValue)
            {
                var testVolume = testPackage.PackageWidth * testPackage.PackageHeight * testPackage.PackageLength;
                if (testVolume > boxPackage.MaxVolume)
                {
                    return(false);
                }
            }

            var boxSizes  = new decimal[] { boxPackage.PackageWidth.Value, boxPackage.PackageHeight.Value, boxPackage.PackageLength.Value };
            var testSizes = new decimal[] { testPackage.PackageWidth.Value, testPackage.PackageHeight.Value, testPackage.PackageLength.Value };

            boxSizes  = boxSizes.OrderByDescending(s => s).ToArray();
            testSizes = testSizes.OrderByDescending(s => s).ToArray();
            for (var i = 0; i < 3; i++)
            {
                if (testSizes[i] > boxSizes[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public ItemPackageDTO ComposePackageSize(IList <DTOOrderItem> items)
        {
            var result = new ItemPackageDTO();

            if (items == null || !items.Any())
            {
                return(result);
            }

            if (items.Any(i => i.PackageHeight == null ||
                          i.PackageWidth == null ||
                          i.PackageLength == null))
            {
                return(result);
            }

            var packages = new List <ItemPackageDTO>();

            foreach (var item in items)
            {
                var package = new ItemPackageDTO()
                {
                    PackageLength = item.PackageLength ?? 1,
                    PackageWidth  = item.PackageWidth ?? 1,
                    PackageHeight = item.PackageHeight ?? 1,
                };
                if (item.Quantity > 1)
                {
                    var minDimension = PriceHelper.Min(PriceHelper.Min(package.PackageLength, package.PackageWidth), package.PackageHeight);
                    if (package.PackageLength == minDimension)
                    {
                        package.PackageLength *= item.Quantity;
                    }
                    else if (package.PackageWidth == minDimension)
                    {
                        package.PackageWidth *= item.Quantity;
                    }
                    else if (package.PackageHeight == minDimension)
                    {
                        package.PackageHeight *= item.Quantity;
                    }
                }

                packages.Add(package);
            }

            result.PackageLength = packages.Max(p => p.PackageLength);
            result.PackageWidth  = packages.Max(p => p.PackageWidth);
            result.PackageHeight = packages.Max(p => p.PackageHeight);

            return(result);
        }
Ejemplo n.º 4
0
        public static bool IsEqualPackages(ItemPackageDTO package1, ItemPackageDTO package2)
        {
            if (package1 == null ||
                package2 == null)
            {
                return(false);
            }

            if (package1.PackageWidth == package1.PackageWidth &&
                package1.PackageHeight == package2.PackageHeight &&
                package1.PackageLength == package2.PackageLength)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public static bool Is1x1x1(ItemPackageDTO package)
        {
            if (!package.PackageHeight.HasValue ||
                !package.PackageLength.HasValue ||
                !package.PackageWidth.HasValue)
            {
                return(true);
            }

            if (package.PackageHeight == 1 &&
                package.PackageLength == 1 &&
                package.PackageWidth == 1)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        public static CallResult <List <ShippingMethodViewModel> > GetShippingOptionsWithRate(IUnitOfWork db,
                                                                                              ILogService log,
                                                                                              ITime time,
                                                                                              IShipmentApi rateProvider,
                                                                                              IShippingService shippingService,
                                                                                              AddressDTO fromAddress,
                                                                                              AddressDTO toAddress,
                                                                                              DateTime shipDate,
                                                                                              int weightLb,
                                                                                              decimal weightOz,
                                                                                              ItemPackageDTO overridePackageSize,
                                                                                              decimal insuredValue,
                                                                                              OrderRateInfo orderInfo)
        {
            var result        = new CallResult <List <ShippingMethodViewModel> >();
            var pickupAddress = fromAddress;

            var rateResult = rateProvider.GetAllRate(
                fromAddress,
                pickupAddress,
                toAddress,
                shipDate,
                (double)(weightLb * 16 + weightOz),
                overridePackageSize,
                insuredValue,
                false,
                orderInfo,
                RetryModeType.Fast);

            if (rateResult.Result != GetRateResultType.Success)
            {
                result.Status  = CallStatus.Fail;
                result.Message = rateResult.Message;
                return(result);
            }

            var methodList = GetShippingMethods(db,
                                                fromAddress.FinalCountry,
                                                toAddress.FinalCountry,
                                                weightLb,
                                                weightOz,
                                                rateProvider.Type);


            result.Data   = new List <ShippingMethodViewModel>();
            result.Status = CallStatus.Success;

            foreach (var method in methodList)
            {
                var rate = rateResult.Rates.FirstOrDefault(r => r.ServiceIdentifier == method.ServiceIdentifier);

                if (rate != null)
                {
                    //var deliveryDays = time.GetBizDaysCount(rate.ShipDate, rate.DeliveryDate);
                    var    deliveryDaysInfo = rate.DeliveryDaysInfo;
                    string providerPrefix   = "";
                    switch ((ShipmentProviderType)method.ShipmentProviderType)
                    {
                    case ShipmentProviderType.Amazon:
                        providerPrefix = "AMZ ";
                        break;

                    case ShipmentProviderType.Stamps:
                        providerPrefix = "";
                        break;

                    case ShipmentProviderType.Dhl:
                        providerPrefix = "";
                        break;

                    case ShipmentProviderType.DhlECom:
                        providerPrefix = "";
                        break;

                    case ShipmentProviderType.IBC:
                        providerPrefix = "";
                        break;

                    case ShipmentProviderType.SkyPostal:
                        providerPrefix = "";
                        break;
                    }

                    var adjustedAmount = shippingService.ApplyCharges(method.Id, rate.Amount);

                    result.Data.Add(new ShippingMethodViewModel()
                    {
                        Id             = method.Id,
                        ProviderPrefix = providerPrefix,
                        Carrier        = method.CarrierName,
                        Name           = ShippingUtils.PrepareMethodNameToDisplay(method.Name, deliveryDaysInfo),
                        Rate           = adjustedAmount,
                    });
                }
            }

            if (result.Data != null)
            {
                result.Data = result.Data.OrderBy(r => r.Rate).ToList();
            }

            return(result);
        }