· 6 years ago · Dec 01, 2019, 06:40 PM
1EatStreetAPI api = new EatStreetAPI("<ACCESS CODE>", "<USER API KEY>");
2
3try {
4 List<Restaurant> results = api.findRestaurants("1234 Example Lane, San Francisco, CA", OrderType.DELIVERY, 2);
5 Restaurant target = results.get(0);
6
7 // Get hours
8 System.out.println(target.getHoursFor("Monday")[0]);
9 System.out.println(target.getHoursFor("tuesday")[0]);
10 System.out.println(target.getHoursFor("WeDNESday")[0]);
11
12 System.out.println(target.getHoursFor("Birthday")[0]);
13
14
15 for(MenuCategory category : target.getMenu()) {
16 System.out.println(category.getName());
17
18 for(MenuItem item : category.getItems()) {
19 System.out.println(" " + item);
20
21 for(CustomizationGroup group : item.getCustomizationGroups()) {
22 System.out.println(" " + group.toString());
23
24 for(Customization customization : group.getCustomizations()) {
25 System.out.println(" " + customization.toString());
26
27 for(CustomizationChoice choice : customization.getCustomizationChoices()) {
28 System.out.println(" " + choice.toString());
29 }
30 }
31 }
32 }
33
34 System.out.println("==========================");
35
36 }
37
38 // Create a new order
39 Restaurant target = results.get(0);
40 Order testOrder = new Order();
41
42 // Set the type of order and the method of payment
43 testOrder.setMethod(OrderType.DELIVERY);
44 testOrder.setPayment(PaymentMethod.CARD);
45
46 // Create a new card to use for the order
47 CreditCard card = new CreditCard();
48 card.setCardholderName("John Doe");
49 card.setCardholderStreetAddress("1234 Example Lane, San Francisco, CA");
50 card.setCardholderZip("12345");
51 card.setCardNumber("1234123412341234");
52 card.setCvv("123");
53
54 // Create a new address for the order
55 Address address = new Address();
56 address.setStreetAddress("1234 Example Lane, San Francisco, CA");
57 address.setCity("San Francisco");
58 address.setState("CA");
59 address.setZip("12345");
60
61
62 // Create a new OrderItem using the api key of a MenuItem. Let's
63 // start by ordering some onions rings
64 OrderItem onionRings = new OrderItem("8591712");
65
66 // Let's also get some french fries
67 OrderItem frenchFries = new OrderItem("8591697");
68
69 // Let's also get a Pita Pizza
70 OrderItem pitaPizza = new OrderItem("8591803");
71
72 // Let's add mozerella cheese all around the pizza
73 OrderCustomizationChoice cheeseAllRound = new OrderCustomizationChoice("28529500");
74 pitaPizza.addCustomization(cheeseAllRound);
75
76 // And green peppers all around
77 OrderCustomizationChoice greenPeppers = new OrderCustomizationChoice("28529516");
78 pitaPizza.addCustomization(greenPeppers);
79
80
81 testOrder.setPhone("123-456-7890"); // Change phone number for order
82 testOrder.setCard(card);
83 testOrder.setAddress(address);
84
85 testOrder.addItem(onionRings);
86 testOrder.addItem(frenchFries);
87 testOrder.addItem(pitaPizza);
88
89 /*
90 * The registered user's phone number, first name, and last name
91 * are used when placing an order. These fields can be overridden
92 * for this single order by setting their fields in the order object
93 *
94 * Only those set will be overriden
95 *
96 * newOrder.setPhone("321-654-8696");
97 * newOrder.setFirstName("Jane");
98 * newOrder.setLastName("Doe")
99 */
100
101 // Validate order
102 target.validateOrder(testOrder);
103
104 System.out.println("\n====TOTALS====");
105 System.out.println(testOrder.getSubTotal());
106 System.out.println(testOrder.getTax());
107 System.out.println(testOrder.getTotal());
108
109 // Send order
110 target.sendOrder(testOrder);
111}
112catch (EatStreetApiException e) {
113 e.printStackTrace();
114}