MEDFORD, Mass. (WPRI) — A discarded Dunkin’ cup led to the arrest of a Medford man who allegedly hit a woman multiple times with a rock, raped her, and left her for dead off a hiking trail, a prosecutor said.

Brady McCue, 28, was arraigned Monday in Somerville District Court on charges of armed assault to murder, assault and battery with a dangerous weapon causing serious bodily injury, kidnapping, and four counts of aggravated rape.

The victim, a 48-year-old woman who was not known to McCue, was walking in the area of Leslie Road Trail Head in Medford around 8 a.m. on Friday at the time of the attack.

The woman told police her attacker was carrying a white coffee cup, a Dunkin’ cup to be exact.

When investigators searched the area, they found the discarded cup with a sticker showing the time and place it was purchased.

Police then were able to obtain security footage from the Dunkin’ in Medford Square and went to a nearby housing complex where people helped investigators identify the suspect as McCue.

In court, prosecutor Carrie Spiros said that within hours after the woman reported the alleged crime, McCue was in custody confessing to it.

He told investigators he hit the woman over the head with a rock and struck her 14 times in the face before trying to duct tape her mouth and drag her into a wooded area to rape her before fleeing the scene.

“Before he purchased the coffee at the Dunkin’ Donuts, he had left his apartment with the intention of hurting someone,” Spiros said. “He later indicated that he left the apartment with the intention to kill someone.”

McCue was ordered to undergo a mental health evaluation to determine competency and criminal responsibility.

As of Friday, the woman was being treated for serious injuries at a Boston hospital and is in stable condition.