United Parcel Service Inc. is finally figuring out how to make money from the surge in online shopping. Revenue per package in the U.S. rose 3 percent in the second quarter, the courier said Thursday as it reported earnings. Analysts were estimating a gain of about 2 percent from the higher prices and new fees on over-sized items the company implemented this year. The sales increase for each parcel is bolstering results as UPS ramps up capital spending by more than a third this year to automate warehouses, add new jets and upgrade technology. The world’s largest package-delivery company is racing to improve the efficiency of residential deliveries, which are booming because of e-commerce—but are far less profitable than shipments to businesses. Online customers buying such products as books, basketballs and bicycles are pushing up costs for each delivery since UPS drivers hand off only 1.1 packages to the average household but more than three to the typical business. That’s fueled investor doubts that the company can capitalize on the e-commerce surge. The shares advanced 2.4 percent to $115 before the start of regular trading in New York. UPS declined 2 percent this year through Wednesday, compared with an 8.9 percent increase in an S&P 500 index of industrial companies. Rival FedEx Corp., which relies more on business-to-business deliveries, had gained 15 percent. The company reaffirmed its profit forecast for 2017. What remains to be seen is how well UPS company copes with the crucial holiday season in the fourth quarter, said Kevin Sterling, an analyst at Seaport Global Securities. “UPS is a show-me story,” Sterling said before the earnings were released. “It all comes down to how they handle Q4 and peak season.” UPS reported adjusted earnings climbed to $1.58 a share in the second quarter, exceeding the $1.47 average of analysts’ estimates. Revenue increased 7.7 percent to $15.8 billion. Analysts expected $15.5 billion.