Esempio n. 1
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. 2
0
 public DimensionItem(string title, UnitOfMeasurementType unitOfMeasurementType)
 {
     Title = title;
     UnitOfMeasurementType = unitOfMeasurementType;
 }
Esempio n. 3
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. 4
0
        static void Main()
        {
            try
            {
                ShipService     shpSvc          = new ShipService();
                ShipmentRequest shipmentRequest = new ShipmentRequest();
                UPSSecurity     upss            = new UPSSecurity();
                UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
                upssSvcAccessToken.AccessLicenseNumber = "Your Access License";
                upss.ServiceAccessToken = upssSvcAccessToken;
                UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
                upssUsrNameToken.Username = "******";
                upssUsrNameToken.Password = "******";
                upss.UsernameToken        = upssUsrNameToken;
                shpSvc.UPSSecurityValue   = upss;
                RequestType request       = new RequestType();
                String[]    requestOption = { "nonvalidate" };
                request.RequestOption   = requestOption;
                shipmentRequest.Request = request;
                ShipmentType shipment = new ShipmentType();
                shipment.Description = "Ship webservice example";
                ShipperType shipper = new ShipperType();
                shipper.ShipperNumber = "Your Shipper Number";
                PaymentInfoType    paymentInfo   = new PaymentInfoType();
                ShipmentChargeType shpmentCharge = new ShipmentChargeType();
                BillShipperType    billShipper   = new BillShipperType();
                billShipper.AccountNumber = "Your Account Number";
                shpmentCharge.BillShipper = billShipper;
                shpmentCharge.Type        = "01";
                ShipmentChargeType[] shpmentChargeArray = { shpmentCharge };
                paymentInfo.ShipmentCharge  = shpmentChargeArray;
                shipment.PaymentInformation = paymentInfo;
                ShipWSSample.ShipWebReference.ShipAddressType shipperAddress = new ShipWSSample.ShipWebReference.ShipAddressType();
                String[] addressLine = { "480 Parkton Plaza" };
                shipperAddress.AddressLine       = addressLine;
                shipperAddress.City              = "Timonium";
                shipperAddress.PostalCode        = "21093";
                shipperAddress.StateProvinceCode = "MD";
                shipperAddress.CountryCode       = "US";
                shipperAddress.AddressLine       = addressLine;
                shipper.Address       = shipperAddress;
                shipper.Name          = "ABC Associates";
                shipper.AttentionName = "ABC Associates";
                ShipPhoneType shipperPhone = new ShipPhoneType();
                shipperPhone.Number = "1234567890";
                shipper.Phone       = shipperPhone;
                shipment.Shipper    = shipper;
                ShipFromType shipFrom = new ShipFromType();
                ShipWSSample.ShipWebReference.ShipAddressType shipFromAddress = new ShipWSSample.ShipWebReference.ShipAddressType();
                String[] shipFromAddressLine = { "Ship From Street" };
                shipFromAddress.AddressLine       = addressLine;
                shipFromAddress.City              = "Timonium";
                shipFromAddress.PostalCode        = "21093";
                shipFromAddress.StateProvinceCode = "MD";
                shipFromAddress.CountryCode       = "US";
                shipFrom.Address       = shipFromAddress;
                shipFrom.AttentionName = "Mr.ABC";
                shipFrom.Name          = "ABC Associates";
                shipment.ShipFrom      = shipFrom;
                ShipToType        shipTo        = new ShipToType();
                ShipToAddressType shipToAddress = new ShipToAddressType();
                String[]          addressLine1  = { "GOERLITZER STR.1" };
                shipToAddress.AddressLine = addressLine1;
                shipToAddress.City        = "Neuss";
                shipToAddress.PostalCode  = "41456";
                shipToAddress.CountryCode = "DE";
                shipTo.Address            = shipToAddress;
                shipTo.AttentionName      = "DEF";
                shipTo.Name = "DEF Associates";
                ShipPhoneType shipToPhone = new ShipPhoneType();
                shipToPhone.Number = "1234567890";
                shipTo.Phone       = shipToPhone;
                shipment.ShipTo    = shipTo;
                ServiceType service = new ServiceType();
                service.Code     = "08";
                shipment.Service = service;

                ShipmentTypeShipmentServiceOptions shpServiceOptions = new ShipmentTypeShipmentServiceOptions();

                /** **** International Forms ***** */
                InternationalFormType internationalForms = new InternationalFormType();

                /** **** Commercial Invoice ***** */
                String[] formTypeList = { "01" };
                internationalForms.FormType = formTypeList;

                /** **** Contacts and Sold To ***** */
                ContactType contacts = new ContactType();

                SoldToType soldTo = new SoldToType();
                soldTo.Option        = "1";
                soldTo.AttentionName = "Sold To Attn Name";
                soldTo.Name          = "Sold To Name";
                PhoneType soldToPhone = new PhoneType();
                soldToPhone.Number    = "1234567890";
                soldToPhone.Extension = "1234";
                soldTo.Phone          = soldToPhone;
                AddressType soldToAddress     = new AddressType();
                String[]    soldToAddressLine = { "34 Queen St" };
                soldToAddress.AddressLine = soldToAddressLine;
                soldToAddress.City        = "Frankfurt";
                soldToAddress.PostalCode  = "60547";
                soldToAddress.CountryCode = "DE";
                soldTo.Address            = soldToAddress;
                contacts.SoldTo           = soldTo;

                internationalForms.Contacts = contacts;

                /** **** Product ***** */
                ProductType product1    = new ProductType();
                String[]    description = { "Product 1" };
                product1.Description       = description;
                product1.CommodityCode     = "111222AA";
                product1.OriginCountryCode = "US";
                UnitType unit = new UnitType();
                unit.Number = "147";
                unit.Value  = "478";
                UnitOfMeasurementType uomProduct = new UnitOfMeasurementType();
                uomProduct.Code        = "BOX";
                uomProduct.Description = "BOX";
                unit.UnitOfMeasurement = uomProduct;
                product1.Unit          = unit;
                ProductWeightType productWeight = new ProductWeightType();
                productWeight.Weight = "10";
                UnitOfMeasurementType uomForWeight = new UnitOfMeasurementType();
                uomForWeight.Code               = "LBS";
                uomForWeight.Description        = "LBS";
                productWeight.UnitOfMeasurement = uomForWeight;
                product1.ProductWeight          = productWeight;
                ProductType[] productList = { product1 };
                internationalForms.Product = productList;

                /** **** InvoiceNumber, InvoiceDate, PurchaseOrderNumber, TermsOfShipment, ReasonForExport, Comments and DeclarationStatement  ***** */
                internationalForms.InvoiceNumber        = "asdf123";
                internationalForms.InvoiceDate          = "20151225";
                internationalForms.PurchaseOrderNumber  = "999jjj777";
                internationalForms.TermsOfShipment      = "CFR";
                internationalForms.ReasonForExport      = "Sale";
                internationalForms.Comments             = "Your Comments";
                internationalForms.DeclarationStatement = "Your Declaration Statement";

                /** **** Discount, FreightCharges, InsuranceCharges, OtherCharges and CurrencyCode  ***** */
                IFChargesType discount = new IFChargesType();
                discount.MonetaryValue      = "100";
                internationalForms.Discount = discount;
                IFChargesType freight = new IFChargesType();
                freight.MonetaryValue             = "50";
                internationalForms.FreightCharges = freight;
                IFChargesType insurance = new IFChargesType();
                insurance.MonetaryValue             = "200";
                internationalForms.InsuranceCharges = insurance;
                OtherChargesType otherCharges = new OtherChargesType();
                otherCharges.MonetaryValue      = "50";
                otherCharges.Description        = "Misc";
                internationalForms.OtherCharges = otherCharges;
                internationalForms.CurrencyCode = "USD";


                shpServiceOptions.InternationalForms = internationalForms;
                shipment.ShipmentServiceOptions      = shpServiceOptions;

                PackageType       package       = new PackageType();
                PackageWeightType packageWeight = new PackageWeightType();
                packageWeight.Weight = "10";
                ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType();
                uom.Code = "LBS";
                packageWeight.UnitOfMeasurement = uom;
                package.PackageWeight           = packageWeight;
                PackagingType packType = new PackagingType();
                packType.Code     = "02";
                package.Packaging = packType;
                PackageType[] pkgArray = { package };
                shipment.Package = pkgArray;
                LabelSpecificationType labelSpec      = new LabelSpecificationType();
                LabelStockSizeType     labelStockSize = new LabelStockSizeType();
                labelStockSize.Height    = "6";
                labelStockSize.Width     = "4";
                labelSpec.LabelStockSize = labelStockSize;
                LabelImageFormatType labelImageFormat = new LabelImageFormatType();
                labelImageFormat.Code              = "GIF";
                labelSpec.LabelImageFormat         = labelImageFormat;
                shipmentRequest.LabelSpecification = labelSpec;
                shipmentRequest.Shipment           = shipment;
                Console.WriteLine(shipmentRequest);
                System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest);
                Console.WriteLine("The transaction was a " + shipmentResponse.Response.ResponseStatus.Description);
                Console.WriteLine("The 1Z number of the new shipment is " + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber);
                Console.ReadKey();
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                Console.WriteLine("");
                Console.WriteLine("---------Ship 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();
            }
        }