Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7473 vikram.rag 1
/******************************************************************************* 
2
 *  Copyright 2008-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
4
 *  
5
 *  You may not use this file except in compliance with the License. 
6
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
7
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
8
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
9
 *  specific language governing permissions and limitations under the License.
10
 * ***************************************************************************** 
11
 * 
12
 *  Marketplace Web Service Orders Java Library
13
 *  API Version: 2011-01-01
14
 * 
15
 */
16
 
17
 
18
 
19
package com.amazonservices.mws.orders.samples;
20
 
21
import java.util.List;
22
import java.util.ArrayList;
23
import com.amazonservices.mws.orders.*;
24
import com.amazonservices.mws.orders.model.*;
25
import com.amazonservices.mws.orders.mock.MarketplaceWebServiceOrdersMock;
26
 
27
/**
28
 *
29
 * Get Order  Samples
30
 *
31
 *
32
 */
33
public class GetOrderSample {
34
 
35
    /**
36
     * Just add few required parameters, and try the service
37
     * Get Order functionality
38
     *
39
     * @param args unused
40
     */
41
    public static void main(String... args) {
42
 
43
        MarketplaceWebServiceOrders service = new MarketplaceWebServiceOrdersClient(
44
					OrdersConfig.accessKeyId, 
45
					OrdersConfig.secretAccessKey, 
46
					OrdersConfig.applicationName, 
47
					OrdersConfig.applicationVersion, 
48
					OrdersConfig.config);
49
 
50
        /************************************************************************
51
         * Uncomment to try out Mock Service that simulates Marketplace Web Service Orders 
52
         * responses without calling Marketplace Web Service Orders  service.
53
         *
54
         * Responses are loaded from local XML files. You can tweak XML files to
55
         * experiment with various outputs during development
56
         *
57
         * XML files available under com/amazonservices/mws/orders/mock tree
58
         *
59
         ***********************************************************************/
60
        //MarketplaceWebServiceOrders 
61
        service = new MarketplaceWebServiceOrdersMock();
62
 
63
        /************************************************************************
64
         * Setup request parameters and uncomment invoke to try out 
65
         * sample for Get Order 
66
         ***********************************************************************/
67
         GetOrderRequest request = new GetOrderRequest();
68
         request.setSellerId(OrdersConfig.sellerId);
69
 
70
         // @TODO: set request parameters here
71
 
72
         invokeGetOrder(service, request);
73
 
74
    }
75
 
76
 
77
 
78
    /**
79
     * Get Order  request sample
80
     * This operation takes up to 50 order ids and returns the corresponding orders.
81
     *   
82
     * @param service instance of MarketplaceWebServiceOrders service
83
     * @param request Action to invoke
84
     */
85
    public static void invokeGetOrder(MarketplaceWebServiceOrders service, GetOrderRequest request) {
86
        try {
87
 
88
            GetOrderResponse response = service.getOrder(request);
89
 
90
 
91
            System.out.println ("GetOrder Action Response");
92
            System.out.println ("=============================================================================");
93
            System.out.println ();
94
 
95
            System.out.println("    GetOrderResponse");
96
            System.out.println();
97
            if (response.isSetGetOrderResult()) {
98
                System.out.println("        GetOrderResult");
99
                System.out.println();
100
                GetOrderResult  getOrderResult = response.getGetOrderResult();
101
                if (getOrderResult.isSetOrders()) {
102
                    System.out.println("            Orders");
103
                    System.out.println();
104
                    OrderList  orders = getOrderResult.getOrders();
105
                    java.util.List<Order> orderList = orders.getOrder();
106
                    for (Order order : orderList) {
107
                        System.out.println("                Order");
108
                        System.out.println();
109
                        if (order.isSetAmazonOrderId()) {
110
                            System.out.println("                    AmazonOrderId");
111
                            System.out.println();
112
                            System.out.println("                        " + order.getAmazonOrderId());
113
                            System.out.println();
114
                        }
115
                        if (order.isSetSellerOrderId()) {
116
                            System.out.println("                    SellerOrderId");
117
                            System.out.println();
118
                            System.out.println("                        " + order.getSellerOrderId());
119
                            System.out.println();
120
                        }
121
                        if (order.isSetPurchaseDate()) {
122
                            System.out.println("                    PurchaseDate");
123
                            System.out.println();
124
                            System.out.println("                        " + order.getPurchaseDate());
125
                            System.out.println();
126
                        }
127
                        if (order.isSetLastUpdateDate()) {
128
                            System.out.println("                    LastUpdateDate");
129
                            System.out.println();
130
                            System.out.println("                        " + order.getLastUpdateDate());
131
                            System.out.println();
132
                        }
133
                        if (order.isSetOrderStatus()) {
134
                            System.out.println("                    OrderStatus");
135
                            System.out.println();
136
                            System.out.println("                        " + order.getOrderStatus().value());
137
                            System.out.println();
138
                        }
139
                        if (order.isSetFulfillmentChannel()) {
140
                            System.out.println("                    FulfillmentChannel");
141
                            System.out.println();
142
                            System.out.println("                        " + order.getFulfillmentChannel().value());
143
                            System.out.println();
144
                        }
145
                        if (order.isSetSalesChannel()) {
146
                            System.out.println("                    SalesChannel");
147
                            System.out.println();
148
                            System.out.println("                        " + order.getSalesChannel());
149
                            System.out.println();
150
                        }
151
                        if (order.isSetOrderChannel()) {
152
                            System.out.println("                    OrderChannel");
153
                            System.out.println();
154
                            System.out.println("                        " + order.getOrderChannel());
155
                            System.out.println();
156
                        }
157
                        if (order.isSetShipServiceLevel()) {
158
                            System.out.println("                    ShipServiceLevel");
159
                            System.out.println();
160
                            System.out.println("                        " + order.getShipServiceLevel());
161
                            System.out.println();
162
                        }
163
                        if (order.isSetShippingAddress()) {
164
                            System.out.println("                    ShippingAddress");
165
                            System.out.println();
166
                            Address  shippingAddress = order.getShippingAddress();
167
                            if (shippingAddress.isSetName()) {
168
                                System.out.println("                        Name");
169
                                System.out.println();
170
                                System.out.println("                            " + shippingAddress.getName());
171
                                System.out.println();
172
                            }
173
                            if (shippingAddress.isSetAddressLine1()) {
174
                                System.out.println("                        AddressLine1");
175
                                System.out.println();
176
                                System.out.println("                            " + shippingAddress.getAddressLine1());
177
                                System.out.println();
178
                            }
179
                            if (shippingAddress.isSetAddressLine2()) {
180
                                System.out.println("                        AddressLine2");
181
                                System.out.println();
182
                                System.out.println("                            " + shippingAddress.getAddressLine2());
183
                                System.out.println();
184
                            }
185
                            if (shippingAddress.isSetAddressLine3()) {
186
                                System.out.println("                        AddressLine3");
187
                                System.out.println();
188
                                System.out.println("                            " + shippingAddress.getAddressLine3());
189
                                System.out.println();
190
                            }
191
                            if (shippingAddress.isSetCity()) {
192
                                System.out.println("                        City");
193
                                System.out.println();
194
                                System.out.println("                            " + shippingAddress.getCity());
195
                                System.out.println();
196
                            }
197
                            if (shippingAddress.isSetCounty()) {
198
                                System.out.println("                        County");
199
                                System.out.println();
200
                                System.out.println("                            " + shippingAddress.getCounty());
201
                                System.out.println();
202
                            }
203
                            if (shippingAddress.isSetDistrict()) {
204
                                System.out.println("                        District");
205
                                System.out.println();
206
                                System.out.println("                            " + shippingAddress.getDistrict());
207
                                System.out.println();
208
                            }
209
                            if (shippingAddress.isSetStateOrRegion()) {
210
                                System.out.println("                        StateOrRegion");
211
                                System.out.println();
212
                                System.out.println("                            " + shippingAddress.getStateOrRegion());
213
                                System.out.println();
214
                            }
215
                            if (shippingAddress.isSetPostalCode()) {
216
                                System.out.println("                        PostalCode");
217
                                System.out.println();
218
                                System.out.println("                            " + shippingAddress.getPostalCode());
219
                                System.out.println();
220
                            }
221
                            if (shippingAddress.isSetCountryCode()) {
222
                                System.out.println("                        CountryCode");
223
                                System.out.println();
224
                                System.out.println("                            " + shippingAddress.getCountryCode());
225
                                System.out.println();
226
                            }
227
                            if (shippingAddress.isSetPhone()) {
228
                                System.out.println("                        Phone");
229
                                System.out.println();
230
                                System.out.println("                            " + shippingAddress.getPhone());
231
                                System.out.println();
232
                            }
233
                        } 
234
                        if (order.isSetOrderTotal()) {
235
                            System.out.println("                    OrderTotal");
236
                            System.out.println();
237
                            Money  orderTotal = order.getOrderTotal();
238
                            if (orderTotal.isSetCurrencyCode()) {
239
                                System.out.println("                        CurrencyCode");
240
                                System.out.println();
241
                                System.out.println("                            " + orderTotal.getCurrencyCode());
242
                                System.out.println();
243
                            }
244
                            if (orderTotal.isSetAmount()) {
245
                                System.out.println("                        Amount");
246
                                System.out.println();
247
                                System.out.println("                            " + orderTotal.getAmount());
248
                                System.out.println();
249
                            }
250
                        } 
251
                        if (order.isSetNumberOfItemsShipped()) {
252
                            System.out.println("                    NumberOfItemsShipped");
253
                            System.out.println();
254
                            System.out.println("                        " + order.getNumberOfItemsShipped());
255
                            System.out.println();
256
                        }
257
                        if (order.isSetNumberOfItemsUnshipped()) {
258
                            System.out.println("                    NumberOfItemsUnshipped");
259
                            System.out.println();
260
                            System.out.println("                        " + order.getNumberOfItemsUnshipped());
261
                            System.out.println();
262
                        }
263
                        if (order.isSetPaymentExecutionDetail()) {
264
                            System.out.println("                    PaymentExecutionDetail");
265
                            System.out.println();
266
                            PaymentExecutionDetailItemList  paymentExecutionDetail = order.getPaymentExecutionDetail();
267
                            java.util.List<PaymentExecutionDetailItem> paymentExecutionDetailItemList = paymentExecutionDetail.getPaymentExecutionDetailItem();
268
                            for (PaymentExecutionDetailItem paymentExecutionDetailItem : paymentExecutionDetailItemList) {
269
                                System.out.println("                        PaymentExecutionDetailItem");
270
                                System.out.println();
271
                                if (paymentExecutionDetailItem.isSetPayment()) {
272
                                    System.out.println("                            Payment");
273
                                    System.out.println();
274
                                    Money  payment = paymentExecutionDetailItem.getPayment();
275
                                    if (payment.isSetCurrencyCode()) {
276
                                        System.out.println("                                CurrencyCode");
277
                                        System.out.println();
278
                                        System.out.println("                                    " + payment.getCurrencyCode());
279
                                        System.out.println();
280
                                    }
281
                                    if (payment.isSetAmount()) {
282
                                        System.out.println("                                Amount");
283
                                        System.out.println();
284
                                        System.out.println("                                    " + payment.getAmount());
285
                                        System.out.println();
286
                                    }
287
                                } 
288
                                if (paymentExecutionDetailItem.isSetPaymentMethod()) {
289
                                    System.out.println("                            PaymentMethod");
290
                                    System.out.println();
291
                                    System.out.println("                                " + paymentExecutionDetailItem.getPaymentMethod());
292
                                    System.out.println();
293
                                }
294
                            }
295
                        } 
296
                        if (order.isSetPaymentMethod()) {
297
                            System.out.println("                    PaymentMethod");
298
                            System.out.println();
299
                            System.out.println("                        " + order.getPaymentMethod().value());
300
                            System.out.println();
301
                        }
302
                        if (order.isSetMarketplaceId()) {
303
                            System.out.println("                    MarketplaceId");
304
                            System.out.println();
305
                            System.out.println("                        " + order.getMarketplaceId());
306
                            System.out.println();
307
                        }
308
                        if (order.isSetBuyerEmail()) {
309
                            System.out.println("                    BuyerEmail");
310
                            System.out.println();
311
                            System.out.println("                        " + order.getBuyerEmail());
312
                            System.out.println();
313
                        }
314
                        if (order.isSetBuyerName()) {
315
                            System.out.println("                    BuyerName");
316
                            System.out.println();
317
                            System.out.println("                        " + order.getBuyerName());
318
                            System.out.println();
319
                        }
320
                        if (order.isSetShipmentServiceLevelCategory()) {
321
                            System.out.println("                    ShipmentServiceLevelCategory");
322
                            System.out.println();
323
                            System.out.println("                        " + order.getShipmentServiceLevelCategory());
324
                            System.out.println();
325
                        }
326
                        if (order.isSetShippedByAmazonTFM()) {
327
                            System.out.println("                    ShippedByAmazonTFM");
328
                            System.out.println();
329
                            System.out.println("                        " + order.isShippedByAmazonTFM());
330
                            System.out.println();
331
                        }
332
                        if (order.isSetTFMShipmentStatus()) {
333
                            System.out.println("                    TFMShipmentStatus");
334
                            System.out.println();
335
                            System.out.println("                        " + order.getTFMShipmentStatus());
336
                            System.out.println();
337
                        }
338
                    }
339
                } 
340
            } 
341
            if (response.isSetResponseMetadata()) {
342
                System.out.println("        ResponseMetadata");
343
                System.out.println();
344
                ResponseMetadata  responseMetadata = response.getResponseMetadata();
345
                if (responseMetadata.isSetRequestId()) {
346
                    System.out.println("            RequestId");
347
                    System.out.println();
348
                    System.out.println("                " + responseMetadata.getRequestId());
349
                    System.out.println();
350
                }
351
            } 
352
            System.out.println();
353
            System.out.println(response.getResponseHeaderMetadata());
354
            System.out.println();
355
 
356
 
357
        } catch (MarketplaceWebServiceOrdersException ex) {
358
 
359
            System.out.println("Caught Exception: " + ex.getMessage());
360
            System.out.println("Response Status Code: " + ex.getStatusCode());
361
            System.out.println("Error Code: " + ex.getErrorCode());
362
            System.out.println("Error Type: " + ex.getErrorType());
363
            System.out.println("Request ID: " + ex.getRequestId());
364
            System.out.println("XML: " + ex.getXML());
365
            System.out.print("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
366
        }
367
    }
368
 
369
}