Esempio n. 1
0
        static void Main()
        {
            try
            {
                FreightRateService freightRateService = new FreightRateService();
                FreightRateRequest freightRateRequest = new FreightRateRequest();
                RequestType        request            = new RequestType();
                String[]           requestOption      = { "RateChecking Option" };
                request.RequestOption      = requestOption;
                freightRateRequest.Request = request;

                /** ****************ShipFrom******************************* */
                ShipFromType shipFrom             = new ShipFromType();
                AddressType  shipFromAddress      = new AddressType();
                String[]     shipFromAddressLines = { "ShipFrom address" };
                shipFromAddress.AddressLine       = shipFromAddressLines;
                shipFromAddress.City              = "ShipFrom city";
                shipFromAddress.StateProvinceCode = "ShipFrom state province code";
                shipFromAddress.PostalCode        = "ShipFrom postal code";
                shipFromAddress.CountryCode       = "ShipFrom country code";
                shipFrom.Address            = shipFromAddress;
                shipFrom.AttentionName      = "ShipFrom attention name";
                shipFrom.Name               = "ShipFrom Name";
                freightRateRequest.ShipFrom = shipFrom;
                /** ****************ShipFrom******************************* */

                /** ****************ShipTo*************************************** */
                ShipToType  shipTo             = new ShipToType();
                AddressType shipToAddress      = new AddressType();
                String[]    shipToAddressLines = { "ShipTo address line" };
                shipToAddress.AddressLine       = shipToAddressLines;
                shipToAddress.City              = "ShipTo city";
                shipToAddress.StateProvinceCode = "ShipTo state province code";
                shipToAddress.PostalCode        = "ShipTo postal code";
                shipToAddress.CountryCode       = "ShipTo country code";
                shipTo.Address            = shipToAddress;
                shipTo.AttentionName      = "ShipTo attention name";
                shipTo.Name               = "ShipTo Name";
                freightRateRequest.ShipTo = shipTo;
                /** ****************ShipTo*************************************** */

                /** ***************PaymentInformationType************************* */
                PaymentInformationType paymentInfo = new PaymentInformationType();
                PayerType payer = new PayerType();
                payer.AttentionName = "Payer attention name";
                payer.Name          = "Payer name";
                payer.ShipperNumber = "Payer shipper number";
                AddressType payerAddress      = new AddressType();
                String[]    payerAddressLines = { "Payer address line" };
                payerAddress.AddressLine       = payerAddressLines;
                payerAddress.City              = "Payer city";
                payerAddress.StateProvinceCode = "Payer state province code";
                payerAddress.PostalCode        = "Payer postal code";
                payerAddress.CountryCode       = "Payer country code";
                payer.Address     = payerAddress;
                paymentInfo.Payer = payer;
                RateCodeDescriptionType shipBillOption = new RateCodeDescriptionType();
                shipBillOption.Code                   = "Ship bill option";
                shipBillOption.Description            = "Ship bill description";
                paymentInfo.ShipmentBillingOption     = shipBillOption;
                freightRateRequest.PaymentInformation = paymentInfo;
                /** ***************PaymentInformationType************************* */

                //Below code use dummy data for referenced. Please update as required


                /** ***************Service************************************** */
                RateCodeDescriptionType service = new RateCodeDescriptionType();
                service.Code               = "309";
                service.Description        = "UPS Ground Freight";
                freightRateRequest.Service = service;
                /** ***************Service************************************** */


                /** **************Commodity************************************* */
                CommodityType      commodity = new CommodityType();
                CommodityValueType commValue = new CommodityValueType();
                commValue.CurrencyCode   = "USD";
                commValue.MonetaryValue  = "5670";
                commodity.CommodityValue = commValue;
                commodity.NumberOfPieces = "20";

                RateCodeDescriptionType packagingType = new RateCodeDescriptionType();
                packagingType.Code        = "BAG";
                packagingType.Description = "BAG";
                commodity.PackagingType   = packagingType;
                WeightType            weight            = new WeightType();
                UnitOfMeasurementType unitOfMeasurement = new UnitOfMeasurementType();
                unitOfMeasurement.Code        = "LBS";
                unitOfMeasurement.Description = "Pounds";
                weight.UnitOfMeasurement      = unitOfMeasurement;
                weight.Value          = "200";
                commodity.Weight      = weight;
                commodity.Description = "LCD TVS";

                CommodityValueType commodityValue = new CommodityValueType();
                commodityValue.CurrencyCode  = "USD";
                commodityValue.MonetaryValue = "100";
                commodity.CommodityValue     = commodityValue;
                commodity.Description        = "LCD TVS";
                commodity.FreightClass       = "60";
                CommodityType[] commodityArray = { commodity };
                freightRateRequest.Commodity = commodityArray;
                /** **************Commodity************************************* */


                /** **************HandlingUnitOne************************************* */
                HandlingUnitType handUnitType = new HandlingUnitType();
                handUnitType.Quantity = "1";
                RateCodeDescriptionType rateCodeDescType = new RateCodeDescriptionType();
                rateCodeDescType.Code              = "SKD";
                rateCodeDescType.Description       = "SKID";
                handUnitType.Type                  = rateCodeDescType;
                freightRateRequest.HandlingUnitOne = handUnitType;

                /** **************HandlingUnitOne************************************* */


                UPSSecurity upss = new UPSSecurity();
                UPSSecurityServiceAccessToken upsSvcToken = new UPSSecurityServiceAccessToken();
                upsSvcToken.AccessLicenseNumber = "Your License Number";
                upss.ServiceAccessToken         = upsSvcToken;
                UPSSecurityUsernameToken upsSecUsrnameToken = new UPSSecurityUsernameToken();
                upsSecUsrnameToken.Username         = "******";
                upsSecUsrnameToken.Password         = "******";
                upss.UsernameToken                  = upsSecUsrnameToken;
                freightRateService.UPSSecurityValue = upss;

                System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                Console.WriteLine(freightRateRequest);
                FreightRateResponse freightRateResponse = freightRateService.ProcessFreightRate(freightRateRequest);
                Console.WriteLine("Response code: " + freightRateResponse.Response.ResponseStatus.Code);
                Console.WriteLine("Response description: " + freightRateResponse.Response.ResponseStatus.Description);
                Console.ReadKey();
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                Console.WriteLine("");
                Console.WriteLine("---------Freight Rate Web Service returns error----------------");
                Console.WriteLine("---------\"Hard\" is user error \"Transient\" is system error----------------");
                Console.WriteLine("SoapException Message= " + ex.Message);
                Console.WriteLine("");
                Console.WriteLine("SoapException Category:Code:Message= " + ex.Detail.LastChild.InnerText);
                Console.WriteLine("");
                Console.WriteLine("SoapException XML String for all= " + ex.Detail.LastChild.OuterXml);
                Console.WriteLine("");
                Console.WriteLine("SoapException StackTrace= " + ex.StackTrace);
                Console.WriteLine("-------------------------");
                Console.WriteLine("");
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                Console.WriteLine("");
                Console.WriteLine("--------------------");
                Console.WriteLine("CommunicationException= " + ex.Message);
                Console.WriteLine("CommunicationException-StackTrace= " + ex.StackTrace);
                Console.WriteLine("-------------------------");
                Console.WriteLine("");
            }
            catch (Exception ex)
            {
                Console.WriteLine("");
                Console.WriteLine("-------------------------");
                Console.WriteLine(" General Exception= " + ex.Message);
                Console.WriteLine(" General Exception-StackTrace= " + ex.StackTrace);
                Console.WriteLine("-------------------------");
            }
            finally
            {
                Console.ReadKey();
            }
        }
Esempio n. 2
0
        private CommodityType WriteSingleCommidityPackage(IShippable pak, bool ignoreDimensions)
        {
            decimal dGirth  = 0;
            decimal dLength = 0;
            decimal dHeight = 0;
            decimal dwidth  = 0;

            CommodityType      commodity = new CommodityType();
            CommodityValueType commValue = new CommodityValueType();

            commodity.NumberOfPieces = pak.QuantityOfItemsInBox.ToString();

            RateCodeDescriptionType packagingType = new RateCodeDescriptionType();

            packagingType.Code        = ((int)GlobalSettings.DefaultPackaging).ToString();
            packagingType.Description = GlobalSettings.DefaultPackaging.ToString();
            commodity.PackagingType   = packagingType;

            WeightType            weight            = new WeightType();
            UnitOfMeasurementType unitOfMeasurement = new UnitOfMeasurementType();

            unitOfMeasurement.Code        = (pak.BoxWeightType == Hotcakes.Shipping.WeightType.Pounds ? "LBS" : "KGS");
            unitOfMeasurement.Description = (pak.BoxWeightType == Hotcakes.Shipping.WeightType.Pounds ? "LBS" : "KGS");

            weight.UnitOfMeasurement = unitOfMeasurement;
            if (pak.BoxWeight > 0)
            {
                weight.Value = Math.Round(pak.BoxWeight, 1).ToString();
            }
            else
            {
                weight.Value = "1";
            }

            commodity.Weight       = weight;
            commodity.Description  = "Weight";
            commodity.FreightClass = GlobalSettings.FreightClass;


            var dimensions = new List <DimensionAmount>();

            if (pak.BoxLengthType == LengthType.Centimeters)
            {
                dimensions.Add(new DimensionAmount(Conversions.CentimetersToInches(pak.BoxLength)));
                dimensions.Add(new DimensionAmount(Conversions.CentimetersToInches(pak.BoxWidth)));
                dimensions.Add(new DimensionAmount(Conversions.CentimetersToInches(pak.BoxHeight)));
            }
            else
            {
                dimensions.Add(new DimensionAmount(pak.BoxLength));
                dimensions.Add(new DimensionAmount(pak.BoxWidth));
                dimensions.Add(new DimensionAmount(pak.BoxWidth));
            }

            var sorted = (from d in dimensions
                          orderby d.Amount descending
                          select d.Amount).ToList();

            dLength = sorted[0];
            dwidth  = sorted[1];
            dHeight = sorted[2];

            dGirth = dwidth + dwidth + dHeight + dHeight;
            //Dimensions can be skipped in latest UPS specs
            if (!ignoreDimensions)
            {
                if (dLength > 0 | dHeight > 0 | dwidth > 0)
                {
                    DimensionsType commondityDimensions = new DimensionsType();

                    commondityDimensions.Height = Math.Round(dHeight, 2).ToString(CultureInfo.InvariantCulture);
                    commondityDimensions.Width  = Math.Round(dwidth, 2).ToString(CultureInfo.InvariantCulture);
                    commondityDimensions.Length = Math.Round(dLength, 2).ToString(CultureInfo.InvariantCulture);

                    UnitOfMeasurementType unitOfMeasurementDimention = new UnitOfMeasurementType();
                    unitOfMeasurementDimention.Code        = "IN";
                    unitOfMeasurementDimention.Description = "Inch";
                    commondityDimensions.UnitOfMeasurement = unitOfMeasurementDimention;

                    commodity.Dimensions = commondityDimensions;
                }
            }
            return(commodity);
        }
Esempio n. 3
0
        static void Main()
        {
            try
            {
                FreightShipService freightShipService = new FreightShipService();
                FreightShipRequest freightShipRequest = new FreightShipRequest();
                RequestType        request            = new RequestType();
                String[]           requestOption      = { "1" };
                request.RequestOption      = requestOption;
                freightShipRequest.Request = request;
                ShipmentType shipment = new ShipmentType();

                /** ****************ShipFrom******************************* */
                ShipFromType           shipFrom        = new ShipFromType();
                FreightShipAddressType shipFromAddress = new FreightShipAddressType();
                String[] shipFromAddressLines          = { "ShipFrom address line" };
                shipFromAddress.AddressLine       = shipFromAddressLines;
                shipFromAddress.City              = "Roswell";
                shipFromAddress.StateProvinceCode = "GA";
                shipFromAddress.PostalCode        = "30076";
                shipFromAddress.CountryCode       = "US";
                shipFrom.Address       = shipFromAddress;
                shipFrom.AttentionName = "XYZ Associates";
                shipFrom.Name          = "XYZ Associates";

                FreightShipPhoneType shipFromPhone = new FreightShipPhoneType();
                shipFromPhone.Number    = "123456789";
                shipFromPhone.Extension = "34567";
                shipFrom.Phone          = shipFromPhone;
                shipFrom.EMailAddress   = "*****@*****.**";
                shipment.ShipFrom       = shipFrom;
                /** ****************ShipFrom******************************* */

                shipment.ShipperNumber = "Your shipper number";

                /** ****************ShipTo*************************************** */
                ShipToType             shipTo        = new ShipToType();
                FreightShipAddressType shipToAddress = new FreightShipAddressType();
                String[] shipToAddressLines          = { "ShipTo address line" };
                shipToAddress.AddressLine       = shipToAddressLines;
                shipToAddress.City              = "Roswell";
                shipToAddress.StateProvinceCode = "GA";
                shipToAddress.PostalCode        = "30076";
                shipToAddress.CountryCode       = "US";
                shipTo.Address       = shipFromAddress;
                shipTo.AttentionName = "PQR Associates";
                shipTo.Name          = "PQR";
                FreightShipPhoneType shipToPhone = new FreightShipPhoneType();
                shipToPhone.Number    = "123456789";
                shipToPhone.Extension = "34567";
                shipTo.Phone          = shipToPhone;
                shipTo.EMailAddress   = "*****@*****.**";
                shipment.ShipTo       = shipTo;
                /** ****************ShipTo*************************************** */

                /** ***************PaymentInformationType************************* */
                PaymentInformationType paymentInfo = new PaymentInformationType();
                PayerType payer = new PayerType();
                payer.AttentionName = "Mr. XYZ";
                payer.Name          = "XYZ Associates";
                FreightShipPhoneType payerPhone = new FreightShipPhoneType();
                payerPhone.Number    = "123456789";
                payerPhone.Extension = "3456";
                payer.Phone          = payerPhone;
                payer.ShipperNumber  = "Your Shipper Number";
                payer.EMailAddress   = "*****@*****.**";

                FreightShipAddressType payerAddress = new FreightShipAddressType();
                String[] payerAddressLines          = { "Payer address line" };
                payerAddress.AddressLine       = payerAddressLines;
                payerAddress.City              = "Roswell";
                payerAddress.StateProvinceCode = "GA";
                payerAddress.PostalCode        = "30075";
                payerAddress.CountryCode       = "US";
                payer.Address     = payerAddress;
                paymentInfo.Payer = payer;
                ShipCodeDescriptionType shipBillOption = new ShipCodeDescriptionType();
                shipBillOption.Code               = "10";
                shipBillOption.Description        = "PREPAID";
                paymentInfo.ShipmentBillingOption = shipBillOption;
                shipment.PaymentInformation       = paymentInfo;
                /** ***************PaymentInformationType************************* */

                /** ***************Service************************************** */
                ShipCodeDescriptionType service = new ShipCodeDescriptionType();
                service.Code        = "309";
                service.Description = "UPS Ground Freight";
                shipment.Service    = service;
                /** ***************Service************************************** */

                //Below sample contains dummy data for your reference
                //Please update dummy date as per your requirement
                /** **************Commodity************************************* */
                CommodityType commodity = new CommodityType();
                commodity.NumberOfPieces = "20";
                NMFCCommodityType nmfcCommodity = new NMFCCommodityType();
                nmfcCommodity.PrimeCode = "132680";
                nmfcCommodity.SubCode   = "02";
                commodity.NMFCCommodity = nmfcCommodity;
                commodity.FreightClass  = "77.5";
                ShipCodeDescriptionType packagingType = new ShipCodeDescriptionType();
                packagingType.Code        = "BAG";
                packagingType.Description = "BAG";
                commodity.PackagingType   = packagingType;
                WeightType weight = new WeightType();
                weight.Value = "200";
                FreightShipUnitOfMeasurementType unitOfMeasurement = new FreightShipUnitOfMeasurementType();
                unitOfMeasurement.Code        = "lbs";
                unitOfMeasurement.Description = "pounds";
                weight.UnitOfMeasurement      = unitOfMeasurement;
                commodity.Weight = weight;
                CommodityValueType commodityValue = new CommodityValueType();
                commodityValue.CurrencyCode  = "USD";
                commodityValue.MonetaryValue = "100";
                commodity.CommodityValue     = commodityValue;
                commodity.Description        = "LCD TVS";
                CommodityType[] commodityArray = { commodity };
                shipment.Commodity = commodityArray;
                /** **************Commodity************************************* */

                /** **************HandlingUnitOne************************** */
                HandlingUnitType handlingUnit = new HandlingUnitType();
                handlingUnit.Quantity = "1";
                ShipCodeDescriptionType handlingUnitType = new ShipCodeDescriptionType();
                handlingUnitType.Code        = "SKD";
                handlingUnitType.Description = "SKID";
                handlingUnit.Type            = handlingUnitType;
                shipment.HandlingUnitOne     = handlingUnit;
                /** **************HandlingUnitOne************************** */

                UPSSecurity upss = new UPSSecurity();
                UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
                upssSvcAccessToken.AccessLicenseNumber = "Your License";
                upss.ServiceAccessToken = upssSvcAccessToken;
                UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
                upssUsrNameToken.Username           = "******";
                upssUsrNameToken.Password           = "******";
                upss.UsernameToken                  = upssUsrNameToken;
                freightShipService.UPSSecurityValue = upss;

                freightShipRequest.Shipment = shipment;

                System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                Console.WriteLine(freightShipRequest);
                FreightShipResponse freightShipResponse = freightShipService.ProcessShipment(freightShipRequest);
                Console.WriteLine("The transaction was a " + freightShipResponse.Response.ResponseStatus.Description);
                Console.WriteLine("The BOLID of the shipment is: " + freightShipResponse.ShipmentResults.BOLID);
                Console.WriteLine("The Shipment number of the shipment is " + freightShipResponse.ShipmentResults.ShipmentNumber);
                Console.ReadKey();
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                Console.WriteLine("");
                Console.WriteLine("---------FreightShip Web Service returns error----------------");
                Console.WriteLine("---------\"Hard\" is user error \"Transient\" is system error----------------");
                Console.WriteLine("SoapException Message= " + ex.Message);
                Console.WriteLine("");
                Console.WriteLine("SoapException Category:Code:Message= " + ex.Detail.LastChild.InnerText);
                Console.WriteLine("");
                Console.WriteLine("SoapException XML String for all= " + ex.Detail.LastChild.OuterXml);
                Console.WriteLine("");
                Console.WriteLine("SoapException StackTrace= " + ex.StackTrace);
                Console.WriteLine("-------------------------");
                Console.WriteLine("");
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                Console.WriteLine("");
                Console.WriteLine("--------------------");
                Console.WriteLine("CommunicationException= " + ex.Message);
                Console.WriteLine("CommunicationException-StackTrace= " + ex.StackTrace);
                Console.WriteLine("-------------------------");
                Console.WriteLine("");
            }
            catch (Exception ex)
            {
                Console.WriteLine("");
                Console.WriteLine("-------------------------");
                Console.WriteLine(" Generaal Exception= " + ex.Message);
                Console.WriteLine(" Generaal Exception-StackTrace= " + ex.StackTrace);
                Console.WriteLine("-------------------------");
            }
            finally
            {
                Console.ReadKey();
            }
        }