private void AddShipToAddress(UPSRateService.ShipmentType shipment, bool isResidentialAddress)
        {
            var shipTo        = new UPSRateService.ShipToType();
            var shipToAddress = new UPSRateService.ShipToAddressType();

            if (!string.IsNullOrEmpty(ShipToAddressLine))
            {
                shipToAddress.AddressLine = new String[] { ShipToAddressLine }
            }
            ;
            if (!string.IsNullOrEmpty(ShipToCity))
            {
                shipToAddress.City = ShipToCity;
            }
            if (!string.IsNullOrEmpty(ShipToPostalCode))
            {
                shipToAddress.PostalCode = ShipToPostalCode;
            }
            if (!string.IsNullOrEmpty(ShipToStateProvinceCode))
            {
                shipToAddress.StateProvinceCode = ShipToStateProvinceCode;
            }
            if (!string.IsNullOrEmpty(ShipToCountryCode))
            {
                shipToAddress.CountryCode = ShipToCountryCode;
            }
            if (isResidentialAddress)
            {
                shipToAddress.ResidentialAddressIndicator = "true";
            }
            shipTo.Address  = shipToAddress;
            shipment.ShipTo = shipTo;
        }
        private void AddShipFromAddress(UPSRateService.ShipmentType shipment)
        {
            var shipFrom        = new UPSRateService.ShipFromType();
            var shipFromAddress = new UPSRateService.AddressType();

            if (!string.IsNullOrEmpty(ShipFromAddressLine))
            {
                shipFromAddress.AddressLine = new String[] { ShipFromAddressLine }
            }
            ;
            if (!string.IsNullOrEmpty(ShipFromCity))
            {
                shipFromAddress.City = ShipFromCity;
            }
            if (!string.IsNullOrEmpty(ShipFromPostalCode))
            {
                shipFromAddress.PostalCode = ShipFromPostalCode;
            }
            if (!string.IsNullOrEmpty(ShipFromStateProvinceCode))
            {
                shipFromAddress.StateProvinceCode = ShipFromStateProvinceCode;
            }
            if (!string.IsNullOrEmpty(ShipFromCountryCode))
            {
                shipFromAddress.CountryCode = ShipFromCountryCode;
            }
            shipFrom.Address  = shipFromAddress;
            shipment.ShipFrom = shipFrom;
        }
Пример #3
0
        public RateResponse CallUPSRateRequest(string serviceCode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, string packagingTypeCode, string currencyCode, decimal unitPrice, bool isResidentialAddress)//, out string requestXML)
        {
            var upsService   = new RateService();
            var rateResponse = new RateResponse();
            var rateRequest  = new RateRequest();

            AddCustomerClassification(rateRequest);
            AddUpsSecurity(upsService);
            var request = new RequestType();

            String[] requestOption = { "Rate" };
            request.RequestOption = requestOption; //this can be Rate or Shop
            rateRequest.Request   = request;
            var shipment = new UPSRateService.ShipmentType();

            AddShipper(shipment);
            AddShipFromAddress(shipment);
            AddShipToAddress(shipment, isResidentialAddress);
            var service = new CodeDescriptionType();

            service.Code     = serviceCode;
            shipment.Service = service;
            var optype = new UPSRateService.ShipmentRatingOptionsType();

            optype.NegotiatedRatesIndicator = string.Empty;
            shipment.ShipmentRatingOptions  = optype;
            AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, packagingTypeCode, currencyCode, shipment);
            AddInvoiceTotalType(Qty, unitPrice, shipment);
            rateRequest.Shipment = shipment;
            rateResponse         = upsService.ProcessRate(rateRequest);
            return(rateResponse);
        }
        private void AddShipper(UPSRateService.ShipmentType shipment)
        {
            var shipper = new UPSRateService.ShipperType();

            shipper.ShipperNumber = ShipperNumber;
            AddShipperAddress(shipper);
            shipment.Shipper = shipper;
        }
        private void AddInvoiceTotalType(int Qty, decimal unitPrice, UPSRateService.ShipmentType shipment)
        {
            var invoiceType = new UPSRateService.InvoiceLineTotalType();

            invoiceType.CurrencyCode = "USD";
            int total = (int)(Qty * unitPrice);

            if (total % 100 > 0)
            {
                total = total + (100 - total % 100);
            }
            invoiceType.MonetaryValue = total.ToString();
            shipment.InvoiceLineTotal = invoiceType;
        }
        private void AddPackageArray(int nrBoxes, int itemsInLastBox, string fullBoxWeight, string partialBoxWeight, int valuePerFullBox, int valuePerPartialBox, inv_detl details, string packagingTypeCode, string currencyCode, UPSRateService.ShipmentType shipment)
        {
            UPSRateService.PackageType[] pkgArray;
            //if (itemsInLastBox > 0)
            //    pkgArray = new UPSRateService.PackageType[nrBoxes];
            //else
            pkgArray = new UPSRateService.PackageType[nrBoxes];

            int tempItemCount = nrBoxes;

            if (itemsInLastBox > 0)
            {
                tempItemCount = tempItemCount - 1;
            }
            for (int i = 0; i < tempItemCount; i++)
            {
                AddFullPackage(fullBoxWeight, valuePerFullBox, details, packagingTypeCode, currencyCode, pkgArray, i);
            }
            if (itemsInLastBox > 0 && !string.IsNullOrEmpty(partialBoxWeight))
            {
                AddPartialPackage(nrBoxes, partialBoxWeight, valuePerPartialBox, details, packagingTypeCode, currencyCode, pkgArray);
            }

            shipment.Package = pkgArray;
        }
 //, out string requestXML)
 public RateResponse CallUPSRateRequest(string serviceCode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, string packagingTypeCode, string currencyCode, decimal unitPrice, bool isResidentialAddress)
 {
     var upsService = new RateService();
     var rateResponse = new RateResponse();
     var rateRequest = new RateRequest();
     AddCustomerClassification(rateRequest);
     AddUpsSecurity(upsService);
     var request = new RequestType();
     String[] requestOption = { "Rate" };
     request.RequestOption = requestOption; //this can be Rate or Shop
     rateRequest.Request = request;
     var shipment = new UPSRateService.ShipmentType();
     AddShipper(shipment);
     AddShipFromAddress(shipment);
     AddShipToAddress(shipment, isResidentialAddress);
     var service = new CodeDescriptionType();
     service.Code = serviceCode;
     shipment.Service = service;
     var optype = new UPSRateService.ShipmentRatingOptionsType();
     optype.NegotiatedRatesIndicator = string.Empty;
     shipment.ShipmentRatingOptions = optype;
     AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, packagingTypeCode, currencyCode, shipment);
     AddInvoiceTotalType(Qty, unitPrice, shipment);
     rateRequest.Shipment = shipment;
     //var serializer = new XmlSerializer(typeof(RateRequest));
     //using (var writer = new StringWriter())
     //{
     //  serializer.Serialize(writer, rateRequest);
     //  requestXML = writer.ToString();
     //}
     rateResponse = upsService.ProcessRate(rateRequest);
     return rateResponse;
 }