Sadly, the war was not avoided. If World War I had been avoided there is a very high probability that World War II would never have come about as the treaty ending WW I set in motion the actions that led to Hitler and Nazi Germany.
Ferdinand, the Austrian archduke who was assassinated in Sarajevo, had long stood out against those who wanted war to solve Austria-Hungary's problems. His death ironically, removed the one man who might have been able to prevent his country from declaring war on Serbia and thus setting the whole chain reaction in motion.
"The War That Ended Peace: The Road to 1914" by Margaret Macmillan, e-book location 302.