Exemplo n.º 1
0
 /// <summary>
 /// Converts dimensions of this package to the given measurement unit
 /// </summary>
 /// <param name="to">The measurement unit to convert to</param>
 public void ConvertDimensions(MeasurementUnit to)
 {
     Height = LocaleHelper.ConvertMeasurement(this.MeasurementUnit, Height, to);
     Width  = LocaleHelper.ConvertMeasurement(this.MeasurementUnit, Width, to);
     Length = LocaleHelper.ConvertMeasurement(this.MeasurementUnit, Length, to);
     this.MeasurementUnit = to;
 }
Exemplo n.º 2
0
        private XmlDocument BuildProviderRequest(Warehouse warehouse, Address destination, Package package)
        {
            ProviderUnits pUnits = GetProviderUnits(warehouse.Country);

            //CREATE PROVIDER REQUEST DOCUMENT
            XmlDocument providerRequest = new XmlDocument();

            providerRequest.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><FDXRateAvailableServicesRequest xmlns:api=\"http://www.fedex.com/fsmapi\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"FDXRateAvailableServicesRequest.xsd\"></FDXRateAvailableServicesRequest>");

            XmlElement nodRequestHeader = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("RequestHeader"));

            XmlUtility.SetElementValue(nodRequestHeader, "AccountNumber", this.AccountNumber);
            XmlUtility.SetElementValue(nodRequestHeader, "MeterNumber", this.MeterNumber);

            //update the shipment settings
            XmlUtility.SetElementValue(providerRequest.DocumentElement, "ShipDate", DateTime.Now.ToString("yyyy'-'MM'-'dd"));
            XmlUtility.SetElementValue(providerRequest.DocumentElement, "DropoffType", DropOffType.ToString());
            XmlUtility.SetElementValue(providerRequest.DocumentElement, "Packaging", PackagingType.ToString());
            XmlUtility.SetElementValue(providerRequest.DocumentElement, "WeightUnits", GetWeightUnitCode(pUnits.WeightUnit));
            XmlUtility.SetElementValue(providerRequest.DocumentElement, "Weight", String.Format("{0:F1}", package.Weight));

            XmlElement nodOriginAddress = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("OriginAddress"));

            XmlUtility.SetElementValue(nodOriginAddress, "StateOrProvinceCode", StringHelper.Truncate(warehouse.Province, 2));
            XmlUtility.SetElementValue(nodOriginAddress, "PostalCode", warehouse.PostalCode);
            XmlUtility.SetElementValue(nodOriginAddress, "CountryCode", warehouse.CountryCode);

            //set the destination
            XmlElement nodDestinationAddress = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("DestinationAddress"));

            XmlUtility.SetElementValue(nodDestinationAddress, "StateOrProvinceCode", StringHelper.Truncate(destination.Province, 2));
            XmlUtility.SetElementValue(nodDestinationAddress, "PostalCode", destination.PostalCode);
            XmlUtility.SetElementValue(nodDestinationAddress, "CountryCode", destination.CountryCode);

            //set payment type
            XmlUtility.SetElementValue(providerRequest.DocumentElement, "Payment/PayorType", "SENDER");

            if (PackagingType == FDXPackagingType.YOURPACKAGING)
            {
                //set the package dimensions
                LSDecimal decPkgLength = package.Length;
                LSDecimal decPkgWidth  = package.Width;
                LSDecimal decPkgHeight = package.Height;

                if (decPkgLength > 0 && decPkgWidth > 0 && decPkgHeight > 0)
                {
                    //REORDER DIMENSIONS
                    LSDecimal[] arrDims = new LSDecimal[3];
                    arrDims[0] = decPkgLength;
                    arrDims[1] = decPkgWidth;
                    arrDims[2] = decPkgHeight;
                    Array.Sort(arrDims);
                    //length is longest dimension;
                    decPkgLength = arrDims[2];
                    //width is middle dimension
                    decPkgWidth = arrDims[1];
                    //height is shortest dimension
                    decPkgHeight = arrDims[0];

                    //trial and error, these were the smallest supported dimensions I could find
                    if (decPkgHeight < LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 2, pUnits.MeasurementUnit))
                    {
                        decPkgHeight = LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 2, pUnits.MeasurementUnit);
                    }
                    if (decPkgLength < LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 7, pUnits.MeasurementUnit))
                    {
                        decPkgLength = LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 7, pUnits.MeasurementUnit);
                    }
                    if (decPkgWidth < LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 4, pUnits.MeasurementUnit))
                    {
                        decPkgWidth = LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 4, pUnits.MeasurementUnit);
                    }

                    XmlElement nodDimensions = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("Dimensions"));
                    XmlUtility.SetElementValue(nodDimensions, "Length", "" + ((int)decPkgLength));
                    XmlUtility.SetElementValue(nodDimensions, "Width", "" + ((int)decPkgWidth));
                    XmlUtility.SetElementValue(nodDimensions, "Height", "" + ((int)decPkgHeight));
                    XmlUtility.SetElementValue(nodDimensions, "Units", GetMeasurementUnitCode(pUnits.MeasurementUnit));
                }
            }

            //CHECK DECLARED VALUE OPTION
            if (this.IncludeDeclaredValue)
            {
                //SET DECLARED VALUE OF SHIPMENT, USE BASE CURRENCY OF STORE
                XmlElement nodDeclaredValue = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("DeclaredValue"));
                XmlUtility.SetElementValue(nodDeclaredValue, "Value", String.Format("{0:F2}", package.RetailValue));
                string currencyCode = Token.Instance.Store.BaseCurrency.ISOCode;
                if (currencyCode.Length != 3)
                {
                    currencyCode = "USD";
                }
                XmlUtility.SetElementValue(nodDeclaredValue, "CurrencyCode", currencyCode);
            }
            //SET RESIDENTIAL FLAG
            if (destination.Residence)
            {
                XmlUtility.SetElementValue(providerRequest.DocumentElement, "SpecialServices/ResidentialDelivery", "1");
            }
            XmlUtility.SetElementValue(providerRequest.DocumentElement, "PackageCount", "1");

            //RETURN THE REQUEST
            return(providerRequest);
        }