private RateResponse CallUPSRateRequest(string scode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, decimal unitPrice, RateService upsService)
        {
            RateResponse rateResponse = new RateResponse();
            try
            {
                RateRequest rateRequest = new RateRequest();
                AddCustomerClassification(rateRequest);
                AddUpsSecurity(upsService);
                UPS_Shipping_Rate.UPSRateService.RequestType request = new RequestType();
                String[] requestOption = { "Rate" };
                request.RequestOption = requestOption;
                rateRequest.Request = request;
                ShipmentType shipment = new ShipmentType();
                AddShipper(shipment);
                AddShipFromAddress(shipment);
                AddShipToAddress(shipment);
                UPS_Shipping_Rate.UPSRateService.CodeDescriptionType service = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType();
                service.Code = scode.ToString();
                shipment.Service = service;
                ShipmentRatingOptionsType optype = new ShipmentRatingOptionsType();
                optype.NegotiatedRatesIndicator = string.Empty;
                shipment.ShipmentRatingOptions = optype;
                AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, shipment);
                AddInvoiceTotalType(Qty, unitPrice, shipment);
                rateRequest.Shipment = shipment;
                //  ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate;
                rateResponse = upsService.ProcessRate(rateRequest);
            }
            catch (Exception ex)
            {

            }
            return rateResponse;
        }
 private void AddShipToAddress(ShipmentType shipment)
 {
     ShipToType shipTo = new ShipToType();
     ShipToAddressType shipToAddress = new ShipToAddressType();
     //shipToAddress.PostalCode = txtZipcode.Text;
     shipToAddress.PostalCode = "19850";
     shipToAddress.CountryCode = "US";
     shipTo.Address = shipToAddress;
     shipment.ShipTo = shipTo;
 }
        private void AddShipper(ShipmentType shipment)
        {
            ShipperType shipper = new ShipperType();
            AddShipperAddress(shipper);

            shipment.Shipper = shipper;
        }
 private void AddShipFromAddress(ShipmentType shipment)
 {
     ShipFromType shipFrom = new ShipFromType();
     AddressType shipFromAddress = new AddressType();
     //  shipFromAddress.AddressLine = new String[] { txtPShipFromAddress.Text };
     shipFromAddress.City = "South El Monte";
     shipFromAddress.PostalCode = "91733";
     shipFromAddress.StateProvinceCode = "CA";
     shipFromAddress.CountryCode = "US";
     shipFrom.Address = shipFromAddress;
     shipment.ShipFrom = shipFrom;
 }
        private void AddPackageArray(int nrBoxes, int itemsInLastBox, string fullBoxWeight, string partialBoxWeight, int valuePerFullBox, int valuePerPartialBox, inv_detl details, ShipmentType shipment)
        {
            PackageType[] pkgArray;
            if (itemsInLastBox > 0)
                pkgArray = new PackageType[nrBoxes + 1];
            else
                pkgArray = new PackageType[nrBoxes];

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

            shipment.Package = pkgArray;
        }
 private static void AddInvoiceTotalType(int Qty, decimal unitPrice, ShipmentType shipment)
 {
     InvoiceLineTotalType invoiceType = new 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;
 }