コード例 #1
0
 private void AddUpsSecurity(ShipService upsShipService)
 {
     var upss = new UPSSecurity();
     AddUpsServiceAccessToken(upss);
     AddUserNameToken(upss);
     upsShipService.UPSSecurityValue = upss;
 }
コード例 #2
0
        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;
        }