private void AddShipToAddress(ShipmentType shipment)
 {
     var shipTo = new ShipToType();
     var shipToAddress = new ShipToAddressType();
     shipToAddress.AddressLine = new String[] { ShipToAddressLine };
     shipToAddress.City = ShipToCity;//txtPShipToCity.Text;
     shipToAddress.PostalCode = ShipToPostalCode;
     shipToAddress.StateProvinceCode = ShipToStateProvinceCode;
     shipToAddress.CountryCode = ShipToCountryCode;
     shipTo.Address = shipToAddress;
     shipTo.Name = ShipToName;
     shipment.ShipTo = shipTo;
 }
 private void AddShipper(ShipmentType shipment)
 {
     var shipper = new ShipperType();
     shipper.ShipperNumber = ShipperNumber;
     shipper.Name = ShipperName;
     AddShipperAddress(shipper);
     shipment.Shipper = shipper;
 }
 private void AddBillShipperAccount(ShipmentType shipment)
 {
     var paymentInfo = new PaymentInfoType();
     var shpmentCharge = new ShipmentChargeType();
     var billShipper = new BillShipperType();
     billShipper.AccountNumber = BillShipperAccountNumber;
     shpmentCharge.BillShipper = billShipper;
     shpmentCharge.Type = ShipmentChargeType;
     ShipmentChargeType[] shpmentChargeArray = { shpmentCharge };
     paymentInfo.ShipmentCharge = shpmentChargeArray;
     shipment.PaymentInformation = paymentInfo;
 }
 private void AddShipFromAddress(ShipmentType shipment)
 {
     var shipFrom = new ShipFromType();
     var shipFromAddress = new ShipAddressType();
     shipFromAddress.AddressLine = new String[] { ShipFromAddressLine };
     shipFromAddress.City = ShipFromCity;
     shipFromAddress.PostalCode = ShipFromPostalCode;
     shipFromAddress.StateProvinceCode = ShipFromStateProvinceCode;
     shipFromAddress.CountryCode = ShipFromCountryCode;
     shipFrom.Address = shipFromAddress;
     shipFrom.Name = ShipFromName;
     shipment.ShipFrom = shipFrom;
 }
        public ShipmentResponse CallUPSShipmentRequest(string serviceCode, int ShipmentID)
        {
            //var dbShipment = ShipmentModule.GetShipmentByID(ShipmentID);
            var shipmentDetails = ShipmentModule.GetShipmentShipmentDetails(ShipmentID);

            var shpSvc = new ShipService();
            var shipmentRequest = new ShipmentRequest();
            AddUpsSecurity(shpSvc);
            var request = new RequestType();
            String[] requestOption = { "1" }; //{ "nonvalidate" };
            request.RequestOption = requestOption;
            shipmentRequest.Request = request;
            var shipment = new ShipmentType();
            shipment.Description = "Ship webservice example";
            AddShipper(shipment);
            AddShipFromAddress(shipment);
            AddShipToAddress(shipment);
            AddBillShipperAccount(shipment);
            //AddPaymentInformation(shipment);

            var service = new ServiceType();
            service.Code = serviceCode;
            shipment.Service = service;

            PackageType[] pkgArray;
            pkgArray = new PackageType[shipmentDetails.Count];
            var i = 0;
            foreach (var box in shipmentDetails)
            {
                AddPackage(box.UnitWeight.Value, Convert.ToInt32(box.UnitPrice), box.DimensionH.Value, box.DimensionD.Value, box.DimensionL.Value, PackagingTypeCode, "USD", pkgArray, i);
                i = i + 1;
            }
            shipment.Package = pkgArray;

            var labelSpec = new LabelSpecificationType();
            var labelStockSize = new LabelStockSizeType();
            labelStockSize.Height = "3";
            labelStockSize.Width = "2";
            labelSpec.LabelStockSize = labelStockSize;
            var labelImageFormat = new LabelImageFormatType();
            labelImageFormat.Code = "GIF";//"SPL";
            labelSpec.LabelImageFormat = labelImageFormat;
            shipmentRequest.LabelSpecification = labelSpec;
            shipmentRequest.Shipment = shipment;

            var shipmentResponse = shpSvc.ProcessShipment(shipmentRequest);
            return shipmentResponse;
        }