How much in advance do you need to purchase a ferry ticket for the 5:00 pm (last) ferry from Amalfi to Sorrento?
Also, can you get the ticket online or in Sorrento beforehand?
I saw in the Naples newspapers last week a report of a fiasco on the ferry returning from Ischia to Naples. It was the last run of the day. So many day trippers showed up that there was no room on the boat for some of them, and that included some who had purchased a return ticket upon arrival in Ischia. You may want to consider taking the next to last boat, just so that you have a backup plan in case you miss the boat for any number of possible reasons.