コード例 #1
0
        protected void btnTest_Click(object sender, EventArgs e)
        {
            this.SaveData();

            var testSettings = new FedExGlobalServiceSettings();

            testSettings.AccountNumber         = this.AccountNumberField.Text;
            testSettings.DefaultDropOffType    = (DropOffType)int.Parse(this.lstDropOffType.SelectedValue);
            testSettings.DefaultPackaging      = (PackageType)int.Parse(this.lstPackaging.SelectedValue);
            testSettings.DiagnosticsMode       = true;
            testSettings.ForceResidentialRates = this.chkResidential.Checked;
            testSettings.MeterNumber           = this.MeterNumberField.Text.Trim();
            testSettings.UseListRates          = this.chkListRates.Checked;
            testSettings.UserKey      = this.KeyField.Text.Trim();
            testSettings.UserPassword = this.PasswordField.Text.Trim();

            var logger = new MerchantTribe.Web.Logging.TextLogger();

            var testSvc = new MerchantTribe.Shipping.FedEx.FedExProvider(testSettings, logger);

            testSvc.Settings.ServiceCode = int.Parse(this.lstServicesTest.SelectedValue);
            testSvc.Settings.Packaging   = (int)testSettings.DefaultPackaging;

            var testShipment = new Shipment();

            testShipment.DestinationAddress = this.DestinationAddress.GetAsAddress();
            testShipment.SourceAddress      = this.SourceAddress.GetAsAddress();
            var testItem = new Shippable();

            testItem.BoxHeight     = decimal.Parse(this.TestHeight.Text);
            testItem.BoxLength     = decimal.Parse(this.TestLength.Text);
            testItem.BoxWidth      = decimal.Parse(this.TestWidth.Text);
            testItem.BoxLengthType = LengthType.Inches;
            testItem.BoxWeight     = decimal.Parse(this.TestWeight.Text);
            testItem.BoxWeightType = MerchantTribe.Shipping.WeightType.Pounds;
            testShipment.Items.Add(testItem);

            StringBuilder sb = new StringBuilder();

            sb.Append("Starting Rate Test at " + DateTime.Now + "<br />");
            var rates = testSvc.RateShipment(testShipment);

            foreach (var r in rates)
            {
                sb.Append("Rate Found: " + r.EstimatedCost.ToString("C") + " | " + r.DisplayName + " (" + r.ServiceCodes + ", " + r.ServiceId + ")<br />");
            }
            sb.Append("<br />");
            sb.Append("LOG:<br />");
            foreach (var m in logger.Messages)
            {
                sb.Append(m + "<br />");
            }
            sb.Append("Finished Rate Test at " + DateTime.Now);
            this.litTestOuput.Text = sb.ToString();
        }
コード例 #2
0
        public IShippable AsIShippable()
        {
            GenerateDimensions();
            var result = new Shippable();

            result.BoxHeight = Height;
            result.BoxLength = Length;
            result.BoxWeight = Weight;
            result.BoxWidth  = Width;

            foreach (var li in Items)
            {
                result.QuantityOfItemsInBox += li.Quantity;
                result.BoxValue             += li.LineTotal;
            }

            return(result);
        }
コード例 #3
0
        private List <IShippable> OptimizeSingleGroup(IShipment shipment)
        {
            const decimal MAXWEIGHT = 70;

            var result       = new List <IShippable>();
            var itemsToSplit = new List <IShippable>();

            foreach (var item in shipment.Items)
            {
                if (IsOversized(item))
                {
                    result.Add(item.CloneShippable());
                }
                else
                {
                    itemsToSplit.Add(item);
                }
            }

            IShippable tempPackage = new Shippable();

            foreach (var pak in itemsToSplit)
            {
                if (MAXWEIGHT - tempPackage.BoxWeight >= pak.BoxWeight)
                {
                    // add to current box
                    tempPackage.BoxWeight            += pak.BoxWeight;
                    tempPackage.QuantityOfItemsInBox += pak.QuantityOfItemsInBox;
                    tempPackage.BoxValue             += pak.BoxValue;
                }
                else
                {
                    // Save the temp package if it has items
                    if (tempPackage.BoxWeight > 0 || tempPackage.QuantityOfItemsInBox > 0)
                    {
                        result.Add(tempPackage.CloneShippable());
                        tempPackage = new Shippable();
                    }

                    // create new box
                    if (pak.BoxWeight > MAXWEIGHT)
                    {
                        //Loop to break up > maxWeight Packages
                        var currentItemsInBox = pak.QuantityOfItemsInBox;
                        var currentWeight     = pak.BoxWeight;

                        while (currentWeight > 0)
                        {
                            if (currentWeight > MAXWEIGHT)
                            {
                                var newP = pak.CloneShippable();
                                newP.BoxWeight = MAXWEIGHT;

                                if (currentItemsInBox > 0)
                                {
                                    currentItemsInBox        -= 1;
                                    newP.QuantityOfItemsInBox = 1;
                                }

                                result.Add(newP);
                                currentWeight = currentWeight - MAXWEIGHT;

                                if (currentWeight < 0)
                                {
                                    currentWeight = 0;
                                }
                            }
                            else
                            {
                                // Create a new shippable box
                                var newP = pak.CloneShippable();
                                newP.BoxWeight = currentWeight;

                                if (currentItemsInBox > 0)
                                {
                                    newP.QuantityOfItemsInBox = currentItemsInBox;
                                }

                                result.Add(newP);
                                currentWeight = 0;
                            }
                        }
                    }
                    else
                    {
                        tempPackage = pak.CloneShippable();
                    }
                }
            }

            // Save the temp package if it has items
            if (tempPackage.BoxWeight > 0 || tempPackage.QuantityOfItemsInBox > 0)
            {
                result.Add(tempPackage.CloneShippable());
                tempPackage = new Shippable();
            }

            return(result);
        }
コード例 #4
0
        public List <Shipment> OptimizeSingleGroup(IShipment shipment)
        {
            decimal MAXWEIGHT = 70;

            // Set Max Weight for Ground Services
            if (Settings.ServiceCode == (int)ServiceType.FEDEXGROUND ||
                Settings.ServiceCode == (int)ServiceType.GROUNDHOMEDELIVERY)
            {
                MAXWEIGHT = 150;
            }

            var result = new List <Shipment>();

            var itemsToSplit = new List <IShippable>();

            foreach (var item in shipment.Items)
            {
                if (IsOversized(item))
                {
                    var s1 = Shipment.CloneAddressesFromInterface(shipment);
                    s1.Items.Add(item.CloneShippable());
                    result.Add(s1);
                }
                else
                {
                    itemsToSplit.Add(item);
                }
            }


            IShippable tempPackage = new Shippable();

            foreach (var pak in itemsToSplit)
            {
                if (MAXWEIGHT - tempPackage.BoxWeight >= pak.BoxWeight)
                {
                    // add to current box
                    tempPackage.BoxWeight            += pak.BoxWeight;
                    tempPackage.QuantityOfItemsInBox += pak.QuantityOfItemsInBox;
                    tempPackage.BoxValue             += pak.BoxValue;
                }
                else
                {
                    // Save the temp package if it has items
                    if (tempPackage.BoxWeight > 0 || tempPackage.QuantityOfItemsInBox > 0)
                    {
                        var s2 = Shipment.CloneAddressesFromInterface(shipment);
                        s2.Items.Add(tempPackage.CloneShippable());
                        result.Add(s2);

                        tempPackage = new Shippable();
                    }

                    // create new box
                    if (pak.BoxWeight > MAXWEIGHT)
                    {
                        //Loop to break up > maxWeight Packages
                        var currentItemsInBox = pak.QuantityOfItemsInBox;
                        var currentWeight     = pak.BoxWeight;

                        while (currentWeight > 0)
                        {
                            if (currentWeight > MAXWEIGHT)
                            {
                                var newP = pak.CloneShippable();
                                newP.BoxWeight = MAXWEIGHT;
                                if (currentItemsInBox > 0)
                                {
                                    currentItemsInBox        -= 1;
                                    newP.QuantityOfItemsInBox = 1;
                                }

                                var s3 = Shipment.CloneAddressesFromInterface(shipment);
                                s3.Items.Add(newP.CloneShippable());
                                result.Add(s3);
                                currentWeight = currentWeight - MAXWEIGHT;
                                if (currentWeight < 0)
                                {
                                    currentWeight = 0;
                                }
                            }
                            else
                            {
                                // Create a new shippable box
                                var newP = pak.CloneShippable();
                                newP.BoxWeight = currentWeight;
                                if (currentItemsInBox > 0)
                                {
                                    newP.QuantityOfItemsInBox = currentItemsInBox;
                                }
                                var s4 = Shipment.CloneAddressesFromInterface(shipment);
                                s4.Items.Add(newP.CloneShippable());
                                result.Add(s4);
                                currentWeight = 0;
                            }
                        }
                    }
                    else
                    {
                        tempPackage = pak.CloneShippable();
                    }
                }
            }

            // Save the temp package if it has items
            if (tempPackage.BoxWeight > 0 || tempPackage.QuantityOfItemsInBox > 0)
            {
                var s5 = Shipment.CloneAddressesFromInterface(shipment);
                s5.Items.Add(tempPackage.CloneShippable());
                result.Add(s5);

                tempPackage = new Shippable();
            }

            return(result);
        }
コード例 #5
0
        public List <IShippable> OptimizePackagesToMaxWeight(IShipment shipment)
        {
            var result       = new List <IShippable>();
            var itemsToSplit = new List <IShippable>();

            // drop off oversize items right away
            foreach (var item in shipment.Items)
            {
                if (IsOversized(item))
                {
                    result.Add(item.CloneShippable());
                }
                else
                {
                    itemsToSplit.Add(item);
                }
            }

            IShippable tempPackage = new Shippable();

            foreach (var pak in itemsToSplit)
            {
                if (_MaxWeight - tempPackage.BoxWeight >= pak.BoxWeight)
                {
                    // add to current box
                    tempPackage.BoxWeight            += pak.BoxWeight;
                    tempPackage.QuantityOfItemsInBox += pak.QuantityOfItemsInBox;
                    tempPackage.BoxValue             += pak.BoxValue;
                }
                else
                {
                    // Save the temp package if it has items
                    if (tempPackage.BoxWeight > 0 || tempPackage.QuantityOfItemsInBox > 0)
                    {
                        result.Add(tempPackage.CloneShippable());
                        tempPackage = new Shippable();
                    }

                    // create new box
                    if (pak.BoxWeight > _MaxWeight)
                    {
                        //Loop to break up > maxWeight Packages
                        var currentItemsInBox = pak.QuantityOfItemsInBox;
                        var currentWeight     = pak.BoxWeight;

                        while (currentWeight > 0)
                        {
                            if (currentWeight > _MaxWeight)
                            {
                                var newP = pak.CloneShippable();
                                newP.BoxWeight = _MaxWeight;
                                if (currentItemsInBox > 0)
                                {
                                    currentItemsInBox        -= 1;
                                    newP.QuantityOfItemsInBox = 1;
                                }
                                result.Add(newP);
                                currentWeight = currentWeight - _MaxWeight;
                                if (currentWeight < 0)
                                {
                                    currentWeight = 0;
                                }
                            }
                            else
                            {
                                // Create a new shippable box
                                var newP = pak.CloneShippable();
                                newP.BoxWeight = currentWeight;
                                if (currentItemsInBox > 0)
                                {
                                    newP.QuantityOfItemsInBox = currentItemsInBox;
                                }
                                result.Add(newP);
                                currentWeight = 0;
                            }
                        }
                    }
                    else
                    {
                        tempPackage = pak.CloneShippable();
                    }
                }
            }

            // Save the temp package if it has items
            if (tempPackage.BoxWeight > 0 || tempPackage.QuantityOfItemsInBox > 0)
            {
                result.Add(tempPackage.CloneShippable());
                tempPackage = new Shippable();
            }

            return(result);
        }
コード例 #6
0
        protected void btnTest_Click(object sender, EventArgs e)
        {
            SaveData();

            var testSettings = new FedExGlobalServiceSettings
            {
                AccountNumber         = AccountNumberField.Text,
                DefaultDropOffType    = (DropOffType)int.Parse(lstDropOffType.SelectedValue),
                DefaultPackaging      = (PackageType)int.Parse(lstPackaging.SelectedValue),
                DiagnosticsMode       = true,
                ForceResidentialRates = chkResidential.Checked,
                MeterNumber           = MeterNumberField.Text.Trim(),
                UserKey                  = KeyField.Text.Trim(),
                UserPassword             = PasswordField.Text.Trim(),
                UseDevelopmentServiceUrl = chkDevelopmentUrl.Checked
            };

            var logger = new TextLogger();

            var testSvc = new FedExProvider(testSettings, logger)
            {
                Settings =
                {
                    ServiceCode = int.Parse(lstServicesTest.SelectedValue),
                    Packaging   = (int)testSettings.DefaultPackaging
                }
            };

            var testShipment = new Shipment
            {
                DestinationAddress = DestinationAddress.GetAsAddress(),
                SourceAddress      = SourceAddress.GetAsAddress()
            };

            var testItem = new Shippable
            {
                BoxHeight     = decimal.Parse(TestHeight.Text),
                BoxLength     = decimal.Parse(TestLength.Text),
                BoxWidth      = decimal.Parse(TestWidth.Text),
                BoxLengthType = LengthType.Inches,
                BoxWeight     = decimal.Parse(TestWeight.Text),
                BoxWeightType = WeightType.Pounds
            };

            testShipment.Items.Add(testItem);

            var sb = new StringBuilder();

            sb.AppendFormat(Localization.GetString("StartingTest"), DateTime.Now);
            sb.Append("<br />");

            var rates = testSvc.RateShipment(testShipment);

            foreach (var r in rates)
            {
                sb.AppendFormat(Localization.GetString("RateFound"), r.EstimatedCost.ToString("C"), r.DisplayName,
                                r.ServiceCodes, r.ServiceId);
                sb.Append("<br />");
            }
            sb.Append("<br />");
            sb.Append(Localization.GetString("Log"));
            sb.Append(":<br />");
            foreach (var m in logger.Messages)
            {
                sb.Append(m + "<br />");
            }
            sb.AppendFormat(Localization.GetString("FinishedTest"), DateTime.Now);

            litTestOuput.Text = sb.ToString();
        }
コード例 #7
0
        protected void btnGetRates_Click(object sender, EventArgs e)
        {
            pnlRates.Visible = true;

            var shipment = new Shipment
            {
                DestinationAddress = { PostalCode = ToZipField.Text.Trim() },
                SourceAddress      = { PostalCode = FromZipField.Text.Trim() }
            };

            // box
            var item = new Shippable();

            var length = 0m;

            decimal.TryParse(LengthField.Text.Trim(), out length);
            var height = 0m;

            decimal.TryParse(HeightField.Text.Trim(), out height);
            var width = 0m;

            decimal.TryParse(WidthField.Text.Trim(), out width);
            var weightPounds = 0m;

            decimal.TryParse(WeightPoundsField.Text.Trim(), out weightPounds);
            var weightOunces = 0m;

            decimal.TryParse(WeightOuncesField.Text.Trim(), out weightOunces);

            item.BoxLength            = length;
            item.BoxHeight            = height;
            item.BoxWidth             = width;
            item.BoxLengthType        = LengthType.Inches;
            item.BoxWeight            = weightPounds + Conversions.OuncesToDecimalPounds(weightOunces);
            item.BoxWeightType        = WeightType.Pounds;
            item.QuantityOfItemsInBox = 1;

            shipment.Items.Add(item);

            // Global Settings
            var globalSettings = new USPostalServiceGlobalSettings
            {
                UserId           = HccApp.CurrentStore.Settings.ShippingUSPostalUserId,
                DiagnosticsMode  = true,
                IgnoreDimensions = false
            };

            // Settings
            var settings = new USPostalServiceSettings();

            var code = new ServiceCode
            {
                Code        = lstServiceTypes.SelectedItem.Value,
                DisplayName = lstServiceTypes.SelectedItem.Text
            };

            var codes = new List <IServiceCode> {
                code
            };

            settings.ServiceCodeFilter = codes;

            var temp = -1;

            int.TryParse(lstPackagingType.SelectedItem.Value, out temp);

            settings.PackageType = (DomesticPackageType)temp;

            // Provider
            var logger   = new TextLogger();
            var provider = new DomesticProvider(globalSettings, logger)
            {
                Settings = settings
            };

            var rates = provider.RateShipment(shipment);

            var sbRates = new StringBuilder();

            sbRates.Append("<ul>");
            foreach (var rate in rates)
            {
                sbRates.Append("<li>");
                sbRates.Append(rate.EstimatedCost.ToString("c"));
                sbRates.Append(" - ");
                sbRates.Append(rate.DisplayName);
                sbRates.Append("</li>");
            }
            sbRates.Append("</ul>");

            litRates.Text = sbRates.ToString();

            var sbMessages = new StringBuilder();

            sbMessages.Append("<ul>");
            foreach (var msg in provider.LatestMessages)
            {
                sbMessages.Append("<li>");
                switch (msg.MessageType)
                {
                case ShippingServiceMessageType.Diagnostics:
                    sbMessages.Append(Localization.GetString("Diagnostics"));
                    break;

                case ShippingServiceMessageType.Information:
                    sbMessages.Append(Localization.GetString("Info"));
                    break;

                case ShippingServiceMessageType.Error:
                    sbMessages.Append(Localization.GetString("Error"));
                    break;
                }
                sbMessages.Append(":");

                sbMessages.Append(HttpUtility.HtmlEncode(string.Concat(msg.Description, " ", msg.Code)));
                sbMessages.Append("</li>");
            }
            sbMessages.Append("</ul>");

            litMessages.Text = sbMessages.ToString();

            litXml.Text = string.Empty;

            while (logger.Messages.Count > 0)
            {
                var tempXml = logger.Messages.Dequeue();
                tempXml      = tempXml.Replace("\n", "<br />");
                tempXml      = tempXml.Replace("\r", "<br />");
                tempXml      = tempXml.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
                litXml.Text += "<li>" + HttpUtility.HtmlEncode(tempXml) + "</li>";
            }
        }